Skip to content

Commit

Permalink
fix: avoid stack in error messages (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed May 28, 2023
1 parent d13e4ae commit b6f5578
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ export default async function stylusLoader(source) {
this.addDependency(path.normalize(error.filename));
}

callback(error);
const obj = new Error(error.message, { cause: error });

obj.stack = null;

callback(obj);

return;
}
Expand Down
13 changes: 12 additions & 1 deletion test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ exports[`loader should emit error when imports files listed as glob in empty dir
exports[`loader should emit error when parse error: errors 1`] = `
[
"ModuleBuildError: Module build failed (from \`replaced original path\`):
ParseError: /test/fixtures/parse-error.styl:3:1",
/test/fixtures/parse-error.styl:3:1",
"ModuleError: Module Error (from \`replaced original path\`):
expected "indent", got "eos"",
]
Expand Down Expand Up @@ -770,6 +770,17 @@ Stylus resolver error: import loop has been found",

exports[`loader should throw an error on circular imports: warnings 1`] = `[]`;

exports[`loader should throw an error: errors 1`] = `
[
"ModuleBuildError: Module build failed (from \`replaced original path\`):
/test/fixtures/broken.styl:1:8",
"ModuleError: Module Error (from \`replaced original path\`):
expected "indent", got ";"",
]
`;

exports[`loader should throw an error: warnings 1`] = `[]`;

exports[`loader should use .json file: css 1`] = `
"@media screen and (min-width: 1px) and (max-width: 400px) {
body {
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/webpackImporter-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`webpackImporter option should throw an error on webpack import when value is "false": errors 1`] = `
[
"ModuleBuildError: Module build failed (from \`replaced original path\`):
Error: /test/fixtures/import-webpack.styl:1:9",
/test/fixtures/import-webpack.styl:1:9",
]
`;

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/broken.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
broken;
9 changes: 9 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1783,4 +1783,13 @@ describe("loader", () => {
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should throw an error", async () => {
const testId = "./broken.styl";
const compiler = getCompiler(testId);
const stats = await compile(compiler);

expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});

0 comments on commit b6f5578

Please sign in to comment.