MCPcopy
hub / github.com/rollup/rollup / handleError

Function handleError

cli/logging.ts:10–59  ·  view source on GitHub ↗
(error: RollupError, recover = false)

Source from the content-addressed store, hash-verified

8 process.stderr.write(`${parameters.join('')}\n`);
9
10export 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}

Callers 7

getConfigPathFunction · 0.90
runRollupFunction · 0.90
reloadConfigFileFunction · 0.90
startFunction · 0.90
closeWithErrorFunction · 0.90
buildFunction · 0.90
watchFunction · 0.90

Calls 4

relativeIdFunction · 0.85
toStringMethod · 0.80
pushMethod · 0.80
stderrFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…