Skip to content

Commit ffab4cd

Browse files
feat: simplify stack info in cli error (#4749)
* fix: remove name and message from stack trace * fix: check whether stack exist * test: tweak test * test: try some change * fix: Write all output in one chunk Apparently, the test fails randomly if the new file is written in response to a log that is not the last one Co-authored-by: Lukas Taegert-Atkinson <[email protected]> Co-authored-by: Lukas Taegert-Atkinson <[email protected]>
1 parent e315ffc commit ffab4cd

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

cli/logging.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,30 @@ export function handleError(error: RollupError, recover = false): void {
1313
const pluginSection = error.plugin ? `(plugin ${error.plugin}) ` : '';
1414
const message = `${pluginSection}${nameSection}${error.message}`;
1515

16-
stderr(bold(red(`[!] ${bold(message.toString())}`)));
16+
const outputLines = [bold(red(`[!] ${bold(message.toString())}`))];
1717

1818
if (error.url) {
19-
stderr(cyan(error.url));
19+
outputLines.push(cyan(error.url));
2020
}
2121

2222
if (error.loc) {
23-
stderr(`${relativeId((error.loc.file || error.id)!)} (${error.loc.line}:${error.loc.column})`);
23+
outputLines.push(
24+
`${relativeId((error.loc.file || error.id)!)} (${error.loc.line}:${error.loc.column})`
25+
);
2426
} else if (error.id) {
25-
stderr(relativeId(error.id));
27+
outputLines.push(relativeId(error.id));
2628
}
2729

2830
if (error.frame) {
29-
stderr(dim(error.frame));
31+
outputLines.push(dim(error.frame));
3032
}
3133

3234
if (error.stack) {
33-
stderr(dim(error.stack));
35+
outputLines.push(dim(error.stack?.replace(`${nameSection}${error.message}\n`, '')));
3436
}
3537

36-
stderr('');
38+
outputLines.push('', '');
39+
stderr(outputLines.join('\n'));
3740

3841
// eslint-disable-next-line unicorn/no-process-exit
3942
if (!recover) process.exit(1);

test/cli/samples/custom-frame-with-pos/_config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ module.exports = {
77
stderr: stderr =>
88
assertIncludes(
99
stderr,
10-
'[!] (plugin at position 1) Error: My error.\n' +
11-
'main.js (1:5)\n' +
12-
'custom code frame\n' +
13-
'Error: My error.'
10+
'[!] (plugin at position 1) Error: My error.\n' + 'main.js (1:5)\n' + 'custom code frame\n'
1411
)
1512
};

test/cli/samples/custom-frame/_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
assertIncludes(
99
stderr,
1010
'[!] (plugin at position 1) Error: My error.\n' +
11-
'main.js\ncustom code frame\nError: My error.\n' +
11+
'main.js\ncustom code frame\n' +
1212
' at Object.'
1313
);
1414
assertIncludes(stderr, 'rollup.config.js:9:19');

test/cli/samples/watch/bundle-error/_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
setTimeout(() => unlinkSync(mainFile), 300);
1717
},
1818
abortOnStderr(data) {
19-
if (data.includes('Error: Unexpected token')) {
19+
if (data.includes('[!] RollupError: Unexpected token')) {
2020
setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500);
2121
return false;
2222
}

0 commit comments

Comments
 (0)