1 | import { red, dim } from 'kleur';
|
2 | import { stderr } from './utils';
|
3 |
|
4 | export default function logError(err) {
|
5 | const error = err.error || err;
|
6 | const description = `${error.name ? error.name + ': ' : ''}${error.message ||
|
7 | error}`;
|
8 | const message = error.plugin
|
9 | ? `(${error.plugin} plugin) ${description}`
|
10 | : description;
|
11 |
|
12 | stderr(red().bold(message));
|
13 |
|
14 | if (error.loc) {
|
15 | stderr();
|
16 | stderr(`at ${error.loc.file}:${error.loc.line}:${error.loc.column}`);
|
17 | }
|
18 |
|
19 | if (error.frame) {
|
20 | stderr();
|
21 | stderr(dim(error.frame));
|
22 | } else if (err.stack) {
|
23 | const headlessStack = error.stack.replace(message, '');
|
24 | stderr(dim(headlessStack));
|
25 | }
|
26 |
|
27 | stderr();
|
28 | }
|