mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
fix: check before writing to errors (#11566)
* fix: check before writing to errors * fix: try using try catches * test: add * chore: changeset * nit: test name
This commit is contained in:
parent
d27cf6df7b
commit
0dcef3ab17
4 changed files with 25 additions and 3 deletions
5
.changeset/violet-drinks-film.md
Normal file
5
.changeset/violet-drinks-film.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes DomException errors not being handled properly
|
|
@ -125,4 +125,10 @@ test.describe('Error display', () => {
|
|||
const message = (await getErrorOverlayContent(page)).message;
|
||||
expect(message).toMatch('can only be used in');
|
||||
});
|
||||
|
||||
test('can handle DomException errors', async ({ page, astro }) => {
|
||||
await page.goto(astro.resolveUrl('/dom-exception'), { waitUntil: 'networkidle' });
|
||||
const message = (await getErrorOverlayContent(page)).message;
|
||||
expect(message).toMatch('The operation was aborted due to timeout');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
await fetch("https://example.com/", {signal: AbortSignal.timeout(5)})
|
||||
---
|
|
@ -26,7 +26,9 @@ export function collectErrorMetadata(e: any, rootFolder?: URL | undefined): Erro
|
|||
err.forEach((error) => {
|
||||
if (e.stack) {
|
||||
const stackInfo = collectInfoFromStacktrace(e);
|
||||
error.stack = stripAnsi(stackInfo.stack);
|
||||
try {
|
||||
error.stack = stripAnsi(stackInfo.stack);
|
||||
} catch {}
|
||||
error.loc = stackInfo.loc;
|
||||
error.plugin = stackInfo.plugin;
|
||||
error.pluginCode = stackInfo.pluginCode;
|
||||
|
@ -72,7 +74,11 @@ export function collectErrorMetadata(e: any, rootFolder?: URL | undefined): Erro
|
|||
// Strip ANSI for `message` property. Note that ESBuild errors may not have the property,
|
||||
// but it will be handled and added below, which is already ANSI-free
|
||||
if (error.message) {
|
||||
error.message = stripAnsi(error.message);
|
||||
try {
|
||||
error.message = stripAnsi(error.message);
|
||||
} catch {
|
||||
// Setting `error.message` can fail here if the message is read-only, which for the vast majority of cases will never happen, however some somewhat obscure cases can cause this to happen.
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -84,7 +90,9 @@ export function collectErrorMetadata(e: any, rootFolder?: URL | undefined): Erro
|
|||
|
||||
// ESBuild can give us a slightly better error message than the one in the error, so let's use it
|
||||
if (text) {
|
||||
err[i].message = text;
|
||||
try {
|
||||
err[i].message = text;
|
||||
} catch {}
|
||||
}
|
||||
|
||||
if (location) {
|
||||
|
|
Loading…
Reference in a new issue