6
6
// This file must be imported before any lazy-loading is being attempted.
7
7
__webpack_public_path__ = `${ window . config ?. assetUrlPrefix ?? '/assets' } /` ;
8
8
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
+ }
12
18
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 } "]` ) ;
16
23
if ( ! msgDiv ) {
17
24
const el = document . createElement ( 'div' ) ;
18
25
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) {
23
30
msgDiv . setAttribute ( `data-global-error-msg-compact` , msgCompact ) ;
24
31
msgDiv . setAttribute ( `data-global-error-msg-count` , msgCount . toString ( ) ) ;
25
32
msgDiv . textContent = msg + ( msgCount > 1 ? ` (${ msgCount } )` : '' ) ;
26
- pageContent . prepend ( msgDiv ) ;
33
+ msgContainer . prepend ( msgDiv ) ;
27
34
}
28
35
29
36
/**
@@ -52,10 +59,12 @@ function processWindowErrorEvent({error, reason, message, type, filename, lineno
52
59
if ( runModeIsProd ) return ;
53
60
}
54
61
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 ;
59
68
}
60
69
61
70
let msg = err ?. message ?? message ;
0 commit comments