From ef3be447cc1ecdfd5a1c6cd49cf7c9a3522c69c4 Mon Sep 17 00:00:00 2001 From: XiaoPi <530257315@qq.com> Date: Fri, 10 Nov 2023 16:21:35 +0800 Subject: [PATCH] fix: allow the name of Rollup Error to be modified (#5240) Co-authored-by: Lukas Taegert-Atkinson --- src/utils/logs.ts | 2 +- .../_config.js | 10 ++++++++++ .../handles-uncaught-errors-under-watch/main.js | 1 + .../rollup.config.js | 16 ++++++++++++++++ test/types.d.ts | 2 +- 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/cli/samples/handles-uncaught-errors-under-watch/_config.js create mode 100644 test/cli/samples/handles-uncaught-errors-under-watch/main.js create mode 100644 test/cli/samples/handles-uncaught-errors-under-watch/rollup.config.js diff --git a/src/utils/logs.ts b/src/utils/logs.ts index d434bf6bb..b424ddbdd 100644 --- a/src/utils/logs.ts +++ b/src/utils/logs.ts @@ -35,7 +35,7 @@ import { export function error(base: Error | RollupLog): never { if (!(base instanceof Error)) { base = Object.assign(new Error(base.message), base); - Object.defineProperty(base, 'name', { value: 'RollupError' }); + Object.defineProperty(base, 'name', { value: 'RollupError', writable: true }); } throw base; } diff --git a/test/cli/samples/handles-uncaught-errors-under-watch/_config.js b/test/cli/samples/handles-uncaught-errors-under-watch/_config.js new file mode 100644 index 000000000..7b78cd56a --- /dev/null +++ b/test/cli/samples/handles-uncaught-errors-under-watch/_config.js @@ -0,0 +1,10 @@ +const { assertIncludes } = require('../../../utils.js'); + +module.exports = defineTest({ + description: 'handles uncaught errors under watch', + command: 'rollup --config rollup.config.js -w', + error: () => true, + stderr(stderr) { + assertIncludes(stderr, 'Uncaught RollupError: LOL'); + } +}); diff --git a/test/cli/samples/handles-uncaught-errors-under-watch/main.js b/test/cli/samples/handles-uncaught-errors-under-watch/main.js new file mode 100644 index 000000000..fd5387381 --- /dev/null +++ b/test/cli/samples/handles-uncaught-errors-under-watch/main.js @@ -0,0 +1 @@ +assert.equal( 42, 42 ); diff --git a/test/cli/samples/handles-uncaught-errors-under-watch/rollup.config.js b/test/cli/samples/handles-uncaught-errors-under-watch/rollup.config.js new file mode 100644 index 000000000..efa2872d9 --- /dev/null +++ b/test/cli/samples/handles-uncaught-errors-under-watch/rollup.config.js @@ -0,0 +1,16 @@ +module.exports = { + input: 'main.js', + output: { + format: 'es' + }, + plugins: [ + { + name: 'test', + buildStart() { + Promise.resolve().then(() => { + this.error('LOL'); + }); + } + } + ] +}; diff --git a/test/types.d.ts b/test/types.d.ts index ff98ca6fa..687c0096b 100644 --- a/test/types.d.ts +++ b/test/types.d.ts @@ -109,7 +109,7 @@ export interface TestConfigCli extends TestConfigBase { * Test the expected error. Assertions about the test output will only * be performed afterward if you return "true" or do not supply this option. */ - error?: (error: RollupError) => boolean | void; + error?: (error: Error) => boolean | void; /** * Execute the bundled code. */