Skip to content

Commit

Permalink
fix(cli): display error when plugin throw an error during serve starting
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder committed Oct 28, 2024
1 parent 8243df6 commit 6e62fa2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/rspack-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export class RspackCLI {
this.getLogger().error(e.message);
process.exit(2);
} else if (e instanceof Error) {
callback?.(e);
if (callback) {
callback?.(e);
} else {
this.getLogger().error(e);
}
return null;
}
throw e;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
mode: "development",
devtool: false,
plugins: [
{
name: "test-plugin",
apply(compiler) {
throw new Error("error in plugin");
}
}
],
devServer: {}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { normalizeStderr, runWatch } from "../../utils/test-utils";

describe("should display plugin error", () => {
it("display error", async () => {
const { stderr } = await runWatch(__dirname, ["serve"], {
killString: /Error: /
});

expect(normalizeStderr(stderr)).toContain("error in plugin");
});
});

0 comments on commit 6e62fa2

Please sign in to comment.