Reorder logic for JavaScript error suppression

This commit is contained in:
David Davies-Payne 2024-05-18 09:08:28 +12:00
parent 8e9ddcf5b9
commit 4c4d39b4e0
1 changed files with 8 additions and 7 deletions

View File

@ -6,7 +6,13 @@
// This file must be imported before any lazy-loading is being attempted.
__webpack_public_path__ = `${window.config?.assetUrlPrefix ?? '/assets'}/`;
// Ignore external and some known internal errors that we are unable to currently fix.
function shouldIgnoreError(err) {
if (!err instanceof Error) return false;
// If the error stack trace does not include the base URL of our script assets, it likely came
// from a browser extension or inline script. Ignore these errors.
if (!err.stack?.includes(assetBaseUrl)) return true;
// Ignore some known internal errors that we are unable to currently fix (eg via Monaco).
const ignorePatterns = [
'/assets/js/monaco.', // https://codeberg.org/forgejo/forgejo/issues/3638 , https://github.com/go-gitea/gitea/issues/30861 , https://github.com/microsoft/monaco-editor/issues/4496
];
@ -70,13 +76,8 @@ function processWindowErrorEvent({error, reason, message, type, filename, lineno
if (runModeIsProd) return;
}
if (err instanceof Error) {
// If the error stack trace does not include the base URL of our script assets, it likely came
// from a browser extension or inline script. Do not show such errors in production.
if (!err.stack?.includes(assetBaseUrl) && runModeIsProd) return;
// Ignore some known errors that we are unable to fix.
if (shouldIgnoreError(err)) return;
}
// In production do not display errors that should be ignored.
if (runModeIsProd && shouldIgnoreError(err)) return;
let msg = err?.message ?? message;
if (lineno) msg += ` (${filename} @ ${lineno}:${colno})`;