From dc8471daf0c2a5264a49b1519e1d992ec94dc921 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 27 May 2020 10:57:38 +0200 Subject: [PATCH] feat(core): Make error message prefixes more descriptive --- packages/babel-core/src/config/full.js | 2 +- packages/babel-core/src/transformation/index.js | 4 ++-- .../test/__snapshots__/option-manager.js.snap | 6 +++--- packages/babel-core/test/async.js | 16 ++++++++-------- .../plugins/build-code-frame-error/exec.js | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/babel-core/src/config/full.js b/packages/babel-core/src/config/full.js index 35b6dc86625a..59faa0927309 100644 --- a/packages/babel-core/src/config/full.js +++ b/packages/babel-core/src/config/full.js @@ -186,7 +186,7 @@ export default gensync<[any], ResolvedConfig | null>(function* loadFullConfig( // There are a few case where thrown errors will try to annotate themselves multiple times, so // to keep things simple we just bail out if re-wrapping the message. if (!/^\[BABEL\]/.test(e.message)) { - e.message = `[BABEL] ${context.filename || "unknown"}: ${e.message}`; + e.message = `[BABEL] ${context.filename || "unknown file"}: ${e.message}`; } throw e; diff --git a/packages/babel-core/src/transformation/index.js b/packages/babel-core/src/transformation/index.js index 970549f9d94e..ba29b285872f 100644 --- a/packages/babel-core/src/transformation/index.js +++ b/packages/babel-core/src/transformation/index.js @@ -42,7 +42,7 @@ export function* run( try { yield* transformFile(file, config.passes); } catch (e) { - e.message = `${opts.filename ?? "unknown"}: ${e.message}`; + e.message = `${opts.filename ?? "unknown file"}: ${e.message}`; if (!e.code) { e.code = "BABEL_TRANSFORM_ERROR"; } @@ -55,7 +55,7 @@ export function* run( ({ outputCode, outputMap } = generateCode(config.passes, file)); } } catch (e) { - e.message = `${opts.filename ?? "unknown"}: ${e.message}`; + e.message = `${opts.filename ?? "unknown file"}: ${e.message}`; if (!e.code) { e.code = "BABEL_GENERATE_ERROR"; } diff --git a/packages/babel-core/test/__snapshots__/option-manager.js.snap b/packages/babel-core/test/__snapshots__/option-manager.js.snap index 423a2dac00b8..381d5c371fa9 100644 --- a/packages/babel-core/test/__snapshots__/option-manager.js.snap +++ b/packages/babel-core/test/__snapshots__/option-manager.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`option-manager config plugin/preset flattening and overriding should throw when an option is following a preset 1`] = ` -"[BABEL] unknown: Unknown option: .useSpread. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options. +"[BABEL] unknown file: Unknown option: .useSpread. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options. - Maybe you meant to use \\"preset\\": [ [\\"./fixtures/option-manager/babel-preset-bar\\", { @@ -12,7 +12,7 @@ To be a valid preset, its name and options should be wrapped in a pair of bracke `; exports[`option-manager config plugin/preset flattening and overriding should throw when an option is provided as a plugin 1`] = ` -"[BABEL] unknown: .useSpread is not a valid Plugin property +"[BABEL] unknown file: .useSpread is not a valid Plugin property - Maybe you meant to use \\"plugin\\": [ [\\"./fixtures/option-manager/babel-plugin-foo\\", { @@ -23,7 +23,7 @@ To be a valid plugin, its name and options should be wrapped in a pair of bracke `; exports[`option-manager config plugin/preset flattening and overriding should throw when an option is provided as a preset 1`] = ` -"[BABEL] unknown: Unknown option: .useBuiltIns. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options. +"[BABEL] unknown file: Unknown option: .useBuiltIns. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options. - Maybe you meant to use \\"preset\\": [ [\\"./fixtures/option-manager/babel-preset-bar\\", { diff --git a/packages/babel-core/test/async.js b/packages/babel-core/test/async.js index 3d834c9e637d..407388ee1637 100644 --- a/packages/babel-core/test/async.js +++ b/packages/babel-core/test/async.js @@ -114,7 +114,7 @@ describe("asynchronicity", () => { expect(() => babel.transformSync(""), ).toThrowErrorMatchingInlineSnapshot( - `"[BABEL] unknown: You appear to be using an async plugin, which your current version of Babel` + + `"[BABEL] unknown file: You appear to be using an async plugin, which your current version of Babel` + ` does not support. If you're using a published plugin, you may need to upgrade your` + ` @babel/core version."`, ); @@ -126,7 +126,7 @@ describe("asynchronicity", () => { await expect( babel.transformAsync(""), ).rejects.toThrowErrorMatchingInlineSnapshot( - `"[BABEL] unknown: You appear to be using an async plugin, which your current version of Babel` + + `"[BABEL] unknown file: You appear to be using an async plugin, which your current version of Babel` + ` does not support. If you're using a published plugin, you may need to upgrade your` + ` @babel/core version."`, ); @@ -140,7 +140,7 @@ describe("asynchronicity", () => { expect(() => babel.transformSync(""), ).toThrowErrorMatchingInlineSnapshot( - `"unknown: You appear to be using an plugin with an async .pre, which your current version` + + `"unknown file: You appear to be using an plugin with an async .pre, which your current version` + ` of Babel does not support. If you're using a published plugin, you may need to upgrade your` + ` @babel/core version."`, ); @@ -152,7 +152,7 @@ describe("asynchronicity", () => { await expect( babel.transformAsync(""), ).rejects.toThrowErrorMatchingInlineSnapshot( - `"unknown: You appear to be using an plugin with an async .pre, which your current version` + + `"unknown file: You appear to be using an plugin with an async .pre, which your current version` + ` of Babel does not support. If you're using a published plugin, you may need to upgrade your` + ` @babel/core version."`, ); @@ -166,7 +166,7 @@ describe("asynchronicity", () => { expect(() => babel.transformSync(""), ).toThrowErrorMatchingInlineSnapshot( - `"unknown: You appear to be using an plugin with an async .post, which your current version` + + `"unknown file: You appear to be using an plugin with an async .post, which your current version` + ` of Babel does not support. If you're using a published plugin, you may need to upgrade your` + ` @babel/core version."`, ); @@ -178,7 +178,7 @@ describe("asynchronicity", () => { await expect( babel.transformAsync(""), ).rejects.toThrowErrorMatchingInlineSnapshot( - `"unknown: You appear to be using an plugin with an async .post, which your current version` + + `"unknown file: You appear to be using an plugin with an async .post, which your current version` + ` of Babel does not support. If you're using a published plugin, you may need to upgrade your` + ` @babel/core version."`, ); @@ -192,7 +192,7 @@ describe("asynchronicity", () => { expect(() => babel.transformSync(""), ).toThrowErrorMatchingInlineSnapshot( - `"[BABEL] unknown: You appear to be using an async plugin, which your current version of Babel` + + `"[BABEL] unknown file: You appear to be using an async plugin, which your current version of Babel` + ` does not support. If you're using a published plugin, you may need to upgrade your` + ` @babel/core version."`, ); @@ -204,7 +204,7 @@ describe("asynchronicity", () => { await expect( babel.transformAsync(""), ).rejects.toThrowErrorMatchingInlineSnapshot( - `"[BABEL] unknown: You appear to be using an async plugin, which your current version of Babel` + + `"[BABEL] unknown file: You appear to be using an async plugin, which your current version of Babel` + ` does not support. If you're using a published plugin, you may need to upgrade your` + ` @babel/core version."`, ); diff --git a/packages/babel-core/test/fixtures/plugins/build-code-frame-error/exec.js b/packages/babel-core/test/fixtures/plugins/build-code-frame-error/exec.js index 0b56fb9bfb43..428d4b56a0c5 100644 --- a/packages/babel-core/test/fixtures/plugins/build-code-frame-error/exec.js +++ b/packages/babel-core/test/fixtures/plugins/build-code-frame-error/exec.js @@ -15,4 +15,4 @@ expect(() => { // hard to assert on ANSI escape codes highlightCode: false, }); -}).toThrow(/^unknown: someMsg\s+> 1 \| function f\(\) {}/); +}).toThrow(/^unknown file: someMsg\s+> 1 \| function f\(\) {}/);