Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simplify stack info in cli error #4749

Merged
merged 6 commits into from Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions cli/logging.ts
Expand Up @@ -13,27 +13,30 @@ export function handleError(error: RollupError, recover = false): void {
const pluginSection = error.plugin ? `(plugin ${error.plugin}) ` : '';
const message = `${pluginSection}${nameSection}${error.message}`;

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

if (error.url) {
stderr(cyan(error.url));
outputLines.push(cyan(error.url));
}

if (error.loc) {
stderr(`${relativeId((error.loc.file || error.id)!)} (${error.loc.line}:${error.loc.column})`);
outputLines.push(
`${relativeId((error.loc.file || error.id)!)} (${error.loc.line}:${error.loc.column})`
);
} else if (error.id) {
stderr(relativeId(error.id));
outputLines.push(relativeId(error.id));
}

if (error.frame) {
stderr(dim(error.frame));
outputLines.push(dim(error.frame));
}

if (error.stack) {
stderr(dim(error.stack));
outputLines.push(dim(error.stack?.replace(`${nameSection}${error.message}\n`, '')));
}

stderr('');
outputLines.push('', '');
stderr(outputLines.join('\n'));

// eslint-disable-next-line unicorn/no-process-exit
if (!recover) process.exit(1);
Expand Down
5 changes: 1 addition & 4 deletions test/cli/samples/custom-frame-with-pos/_config.js
Expand Up @@ -7,9 +7,6 @@ module.exports = {
stderr: stderr =>
assertIncludes(
stderr,
'[!] (plugin at position 1) Error: My error.\n' +
'main.js (1:5)\n' +
'custom code frame\n' +
'Error: My error.'
'[!] (plugin at position 1) Error: My error.\n' + 'main.js (1:5)\n' + 'custom code frame\n'
)
};
2 changes: 1 addition & 1 deletion test/cli/samples/custom-frame/_config.js
Expand Up @@ -8,7 +8,7 @@ module.exports = {
assertIncludes(
stderr,
'[!] (plugin at position 1) Error: My error.\n' +
'main.js\ncustom code frame\nError: My error.\n' +
'main.js\ncustom code frame\n' +
' at Object.'
);
assertIncludes(stderr, 'rollup.config.js:9:19');
Expand Down
2 changes: 1 addition & 1 deletion test/cli/samples/watch/bundle-error/_config.js
Expand Up @@ -16,7 +16,7 @@ module.exports = {
setTimeout(() => unlinkSync(mainFile), 300);
},
abortOnStderr(data) {
if (data.includes('Error: Unexpected token')) {
if (data.includes('[!] RollupError: Unexpected token')) {
setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500);
return false;
}
Expand Down