(error: RollupError, recover = false)
| 8 | process.stderr.write(`${parameters.join('')}\n`); |
| 9 | |
| 10 | export function handleError(error: RollupError, recover = false): void { |
| 11 | const name = error.name || (error.cause as Error)?.name; |
| 12 | const nameSection = name ? `${name}: ` : ''; |
| 13 | const pluginSection = error.plugin ? `(plugin ${error.plugin}) ` : ''; |
| 14 | const message = `${pluginSection}${nameSection}${error.message}`; |
| 15 | |
| 16 | const outputLines = [bold(red(`[!] ${bold(message.toString())}`))]; |
| 17 | |
| 18 | if (error.url) { |
| 19 | outputLines.push(cyan(error.url)); |
| 20 | } |
| 21 | |
| 22 | if (error.loc) { |
| 23 | outputLines.push( |
| 24 | `${relativeId((error.loc.file || error.id)!)} (${error.loc.line}:${error.loc.column})` |
| 25 | ); |
| 26 | } else if (error.id) { |
| 27 | outputLines.push(relativeId(error.id)); |
| 28 | } |
| 29 | |
| 30 | if (error.frame) { |
| 31 | outputLines.push(dim(error.frame)); |
| 32 | } |
| 33 | |
| 34 | if (error.stack) { |
| 35 | outputLines.push(dim(error.stack?.replace(`${nameSection}${error.message}\n`, ''))); |
| 36 | } |
| 37 | |
| 38 | // ES2022: Error.prototype.cause is optional |
| 39 | if (error.cause) { |
| 40 | let cause = error.cause as Error | undefined; |
| 41 | const causeErrorLines = []; |
| 42 | let indent = ''; |
| 43 | |
| 44 | while (cause) { |
| 45 | indent += ' '; |
| 46 | const message = cause.stack || cause; |
| 47 | causeErrorLines.push(...`[cause] ${message}`.split('\n').map(line => indent + line)); |
| 48 | |
| 49 | cause = cause.cause as Error | undefined; |
| 50 | } |
| 51 | |
| 52 | outputLines.push(dim(causeErrorLines.join('\n'))); |
| 53 | } |
| 54 | |
| 55 | outputLines.push('', ''); |
| 56 | stderr(outputLines.join('\n')); |
| 57 | |
| 58 | if (!recover) process.exit(1); |
| 59 | } |
no test coverage detected
searching dependent graphs…