Skip to content

Commit

Permalink
feat(core): Make error message prefixes more descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 27, 2020
1 parent b457f52 commit dc8471d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/full.js
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/src/transformation/index.js
Expand Up @@ -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";
}
Expand All @@ -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";
}
Expand Down
6 changes: 3 additions & 3 deletions 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\\", {
Expand All @@ -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\\", {
Expand All @@ -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\\", {
Expand Down
16 changes: 8 additions & 8 deletions packages/babel-core/test/async.js
Expand Up @@ -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."`,
);
Expand All @@ -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."`,
);
Expand All @@ -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."`,
);
Expand All @@ -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."`,
);
Expand All @@ -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."`,
);
Expand All @@ -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."`,
);
Expand All @@ -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."`,
);
Expand All @@ -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."`,
);
Expand Down
Expand Up @@ -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\(\) {}/);

0 comments on commit dc8471d

Please sign in to comment.