Skip to content

feat: add cause for errorObject #5518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client-src/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,9 @@
*/
const handleError = (error, fallbackMessage) => {
const errorObject =
error instanceof Error ? error : new Error(error || fallbackMessage);
error instanceof Error
? error
: new Error(error || fallbackMessage, { cause: error });

Check warning on line 642 in client-src/overlay.js

View check run for this annotation

Codecov / codecov/patch

client-src/overlay.js#L641-L642

Added lines #L641 - L642 were not covered by tests

const shouldDisplay =
typeof options.catchRuntimeError === "function"
Expand Down
47 changes: 47 additions & 0 deletions test/e2e/overlay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,53 @@ describe("overlay", () => {
}
});

it("should not show filtered promise rejection with specific error cause", async () => {
const compiler = webpack(config);

const server = new Server(
{
port,
client: {
overlay: {
runtimeErrors: (error) =>
!/Injected/.test(error.cause.error.message),
},
},
},
compiler,
);

await server.start();

const { page, browser } = await runBrowser();

try {
await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});

await page.addScriptTag({
content: `(function throwError() {
setTimeout(function () {
Promise.reject({ error: new Error('Injected async error') });
}, 0);
})();`,
});

// Delay for the overlay to appear
await delay(1000);

const overlayHandle = await page.$("#webpack-dev-server-client-overlay");

expect(overlayHandle).toBe(null);
} catch (error) {
throw error;
} finally {
await browser.close();
await server.stop();
}
});

it('should show overlay when "Content-Security-Policy" is "default-src \'self\'" was used', async () => {
const compiler = webpack({ ...config, devtool: false });

Expand Down
Loading