diff --git a/cli/logging.ts b/cli/logging.ts index aeb1f9e3770..fd1100c51f4 100644 --- a/cli/logging.ts +++ b/cli/logging.ts @@ -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); diff --git a/test/cli/samples/custom-frame-with-pos/_config.js b/test/cli/samples/custom-frame-with-pos/_config.js index e778c6418a4..2af0a903e4d 100644 --- a/test/cli/samples/custom-frame-with-pos/_config.js +++ b/test/cli/samples/custom-frame-with-pos/_config.js @@ -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' ) }; diff --git a/test/cli/samples/custom-frame/_config.js b/test/cli/samples/custom-frame/_config.js index 6754f50bfe2..bd3f7c35c69 100644 --- a/test/cli/samples/custom-frame/_config.js +++ b/test/cli/samples/custom-frame/_config.js @@ -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'); diff --git a/test/cli/samples/watch/bundle-error/_config.js b/test/cli/samples/watch/bundle-error/_config.js index f8a2ebeab1a..c00b2e0161b 100644 --- a/test/cli/samples/watch/bundle-error/_config.js +++ b/test/cli/samples/watch/bundle-error/_config.js @@ -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; }