summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2024-05-06 00:53:09 +0800
committerGitHub <noreply@github.com>2024-05-06 00:53:09 +0800
commitbb7150c30d51fb0f14c98ad519af73717ddd3044 (patch)
treea2f82563028b9fb0c7448370a911711ba9c32029
parent60fa2a5960e8c51c164f4083fac6707c54a747ba (diff)
downloadgitea-bb7150c30d51fb0f14c98ad519af73717ddd3044.tar.gz
gitea-bb7150c30d51fb0f14c98ad519af73717ddd3044.zip
Do not show monaco JS errors (#30862) (#30866)
Backport #30862 by wxiaoguang Fix #30861 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
-rw-r--r--web_src/js/bootstrap.js31
1 files changed, 20 insertions, 11 deletions
diff --git a/web_src/js/bootstrap.js b/web_src/js/bootstrap.js
index e466d0b169..8339b4bd82 100644
--- a/web_src/js/bootstrap.js
+++ b/web_src/js/bootstrap.js
@@ -6,13 +6,20 @@
// This file must be imported before any lazy-loading is being attempted.
__webpack_public_path__ = `${window.config?.assetUrlPrefix ?? '/assets'}/`;
-export function showGlobalErrorMessage(msg) {
- const pageContent = document.querySelector('.page-content');
- if (!pageContent) return;
+function shouldIgnoreError(err) {
+ const ignorePatterns = [
+ '/assets/js/monaco.', // https://github.com/go-gitea/gitea/issues/30861 , https://github.com/microsoft/monaco-editor/issues/4496
+ ];
+ for (const pattern of ignorePatterns) {
+ if (err.stack?.includes(pattern)) return true;
+ }
+ return false;
+}
- // compact the message to a data attribute to avoid too many duplicated messages
- const msgCompact = msg.replace(/\W/g, '').trim();
- let msgDiv = pageContent.querySelector(`.js-global-error[data-global-error-msg-compact="${msgCompact}"]`);
+export function showGlobalErrorMessage(msg) {
+ const msgContainer = document.querySelector('.page-content') ?? document.body;
+ const msgCompact = msg.replace(/\W/g, '').trim(); // compact the message to a data attribute to avoid too many duplicated messages
+ let msgDiv = msgContainer.querySelector(`.js-global-error[data-global-error-msg-compact="${msgCompact}"]`);
if (!msgDiv) {
const el = document.createElement('div');
el.innerHTML = `<div class="ui container negative message center aligned js-global-error tw-mt-[15px] tw-whitespace-pre-line"></div>`;
@@ -23,7 +30,7 @@ export function showGlobalErrorMessage(msg) {
msgDiv.setAttribute(`data-global-error-msg-compact`, msgCompact);
msgDiv.setAttribute(`data-global-error-msg-count`, msgCount.toString());
msgDiv.textContent = msg + (msgCount > 1 ? ` (${msgCount})` : '');
- pageContent.prepend(msgDiv);
+ msgContainer.prepend(msgDiv);
}
/**
@@ -52,10 +59,12 @@ function processWindowErrorEvent({error, reason, message, type, filename, lineno
if (runModeIsProd) return;
}
- // 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 instanceof Error && !err.stack?.includes(assetBaseUrl) && 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 are unable to fix
+ if (shouldIgnoreError(err)) return;
}
let msg = err?.message ?? message;