| 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 + ': ' : ''}${ |
| 7 | error.message || error |
| 8 | }`; |
| 9 | const message = error.plugin |
| 10 | ? `(${error.plugin} plugin) ${description}` |
| 11 | : description; |
| 12 | |
| 13 | stderr(red().bold(message)); |
| 14 | |
| 15 | if (error.loc) { |
| 16 | stderr(); |
| 17 | stderr(`at ${error.loc.file}:${error.loc.line}:${error.loc.column}`); |
| 18 | } |
| 19 | |
| 20 | if (error.frame) { |
| 21 | stderr(); |
| 22 | stderr(dim(error.frame)); |
| 23 | } else if (err.stack) { |
| 24 | const headlessStack = error.stack.replace(message, ''); |
| 25 | stderr(dim(headlessStack)); |
| 26 | } |
| 27 | |
| 28 | stderr(); |
| 29 | } |