66// This file must be imported before any lazy-loading is being attempted.
77__webpack_public_path__ = `${ window . config ?. assetUrlPrefix ?? '/assets' } /` ;
88
9- export function showGlobalErrorMessage ( msg ) {
10- const pageContent = document . querySelector ( '.page-content' ) ;
11- if ( ! pageContent ) return ;
9+ function shouldIgnoreError ( err ) {
10+ const ignorePatterns = [
11+ '/assets/js/monaco.' , // https://github.com/go-gitea/gitea/issues/30861 , https://github.com/microsoft/monaco-editor/issues/4496
12+ ] ;
13+ for ( const pattern of ignorePatterns ) {
14+ if ( err . stack ?. includes ( pattern ) ) return true ;
15+ }
16+ return false ;
17+ }
1218
13- // compact the message to a data attribute to avoid too many duplicated messages
14- const msgCompact = msg . replace ( / \W / g, '' ) . trim ( ) ;
15- let msgDiv = pageContent . querySelector ( `.js-global-error[data-global-error-msg-compact="${ msgCompact } "]` ) ;
19+ export function showGlobalErrorMessage ( msg ) {
20+ const msgContainer = document . querySelector ( '.page-content' ) ?? document . body ;
21+ const msgCompact = msg . replace ( / \W / g, '' ) . trim ( ) ; // compact the message to a data attribute to avoid too many duplicated messages
22+ let msgDiv = msgContainer . querySelector ( `.js-global-error[data-global-error-msg-compact="${ msgCompact } "]` ) ;
1623 if ( ! msgDiv ) {
1724 const el = document . createElement ( 'div' ) ;
1825 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) {
2330 msgDiv . setAttribute ( `data-global-error-msg-compact` , msgCompact ) ;
2431 msgDiv . setAttribute ( `data-global-error-msg-count` , msgCount . toString ( ) ) ;
2532 msgDiv . textContent = msg + ( msgCount > 1 ? ` (${ msgCount } )` : '' ) ;
26- pageContent . prepend ( msgDiv ) ;
33+ msgContainer . prepend ( msgDiv ) ;
2734}
2835
2936/**
@@ -52,10 +59,12 @@ function processWindowErrorEvent({error, reason, message, type, filename, lineno
5259 if ( runModeIsProd ) return ;
5360 }
5461
55- // If the error stack trace does not include the base URL of our script assets, it likely came
56- // from a browser extension or inline script. Do not show such errors in production.
57- if ( err instanceof Error && ! err . stack ?. includes ( assetBaseUrl ) && runModeIsProd ) {
58- return ;
62+ if ( err instanceof Error ) {
63+ // If the error stack trace does not include the base URL of our script assets, it likely came
64+ // from a browser extension or inline script. Do not show such errors in production.
65+ if ( ! err . stack ?. includes ( assetBaseUrl ) && runModeIsProd ) return ;
66+ // Ignore some known errors that are unable to fix
67+ if ( shouldIgnoreError ( err ) ) return ;
5968 }
6069
6170 let msg = err ?. message ?? message ;
0 commit comments