From a4e5c9ae432360386d002585d7aa1e9281d45191 Mon Sep 17 00:00:00 2001 From: TrickyPi <530257315@qq.com> Date: Tue, 13 Dec 2022 11:13:10 +0800 Subject: [PATCH 1/5] fix: remove name and message from stack trace --- cli/logging.ts | 2 +- test/cli/samples/custom-frame-with-pos/_config.js | 5 +---- test/cli/samples/custom-frame/_config.js | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cli/logging.ts b/cli/logging.ts index aeb1f9e3770..964a6a8e348 100644 --- a/cli/logging.ts +++ b/cli/logging.ts @@ -30,7 +30,7 @@ export function handleError(error: RollupError, recover = false): void { } if (error.stack) { - stderr(dim(error.stack)); + stderr(dim(error.stack.replace(`${nameSection}${error.message}\n`, ''))); } stderr(''); 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'); From eaa82e32c765e88b1faecd6fc3b73570cbe3e039 Mon Sep 17 00:00:00 2001 From: TrickyPi <530257315@qq.com> Date: Tue, 13 Dec 2022 11:36:51 +0800 Subject: [PATCH 2/5] fix: check whether stack exist --- cli/logging.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/logging.ts b/cli/logging.ts index 964a6a8e348..781b9975bb5 100644 --- a/cli/logging.ts +++ b/cli/logging.ts @@ -30,7 +30,7 @@ export function handleError(error: RollupError, recover = false): void { } if (error.stack) { - stderr(dim(error.stack.replace(`${nameSection}${error.message}\n`, ''))); + stderr(dim(error.stack?.replace(`${nameSection}${error.message}\n`, ''))); } stderr(''); From a98df37c8154887a9a3a3b32ce283ce9022eed81 Mon Sep 17 00:00:00 2001 From: TrickyPi <530257315@qq.com> Date: Tue, 13 Dec 2022 17:16:09 +0800 Subject: [PATCH 3/5] test: tweak test --- test/cli/samples/watch/bundle-error/_config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From 7e8f8d36444a86a2fb32b89029128ccf13b54da8 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 15 Dec 2022 06:26:37 +0100 Subject: [PATCH 4/5] test: try some change --- test/cli/samples/watch/bundle-error/_config.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/cli/samples/watch/bundle-error/_config.js b/test/cli/samples/watch/bundle-error/_config.js index c00b2e0161b..42e956bd11d 100644 --- a/test/cli/samples/watch/bundle-error/_config.js +++ b/test/cli/samples/watch/bundle-error/_config.js @@ -16,12 +16,19 @@ module.exports = { setTimeout(() => unlinkSync(mainFile), 300); }, abortOnStderr(data) { - if (data.includes('[!] RollupError: Unexpected token')) { - setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500); + // trigger this when the stack trace is written + if (data.includes('at error')) { + console.log('TRIGGER WRITE FILE'); + setTimeout(() => { + console.log('ACTUAL WRITE'); + atomicWriteFileSync(mainFile, 'export default 42;'); + }, 500); return false; - } - if (data.includes('created _actual')) { + } else if (data.includes('created _actual')) { + console.log('DONE'); return true; + } else { + console.log('NO TRIGGER:', data); } } }; From f91c445c65953e2681d004d4f3e15cca13cc2f84 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 16 Dec 2022 09:08:12 +0100 Subject: [PATCH 5/5] 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 --- cli/logging.ts | 17 ++++++++++------- test/cli/samples/watch/bundle-error/_config.js | 15 ++++----------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/cli/logging.ts b/cli/logging.ts index 781b9975bb5..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?.replace(`${nameSection}${error.message}\n`, ''))); + 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/watch/bundle-error/_config.js b/test/cli/samples/watch/bundle-error/_config.js index 42e956bd11d..c00b2e0161b 100644 --- a/test/cli/samples/watch/bundle-error/_config.js +++ b/test/cli/samples/watch/bundle-error/_config.js @@ -16,19 +16,12 @@ module.exports = { setTimeout(() => unlinkSync(mainFile), 300); }, abortOnStderr(data) { - // trigger this when the stack trace is written - if (data.includes('at error')) { - console.log('TRIGGER WRITE FILE'); - setTimeout(() => { - console.log('ACTUAL WRITE'); - atomicWriteFileSync(mainFile, 'export default 42;'); - }, 500); + if (data.includes('[!] RollupError: Unexpected token')) { + setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500); return false; - } else if (data.includes('created _actual')) { - console.log('DONE'); + } + if (data.includes('created _actual')) { return true; - } else { - console.log('NO TRIGGER:', data); } } };