@@ -149,30 +149,32 @@ window.onunhandledrejection = async function onUnhandledRejection(event) {
149149
150150// Monkeypatch p5._friendlyError
151151const { _report } = window . p5 ;
152- window . p5 . _report = function resolvedReport ( message , method , color ) {
153- const urls = Object . keys ( window . objectUrls ) ;
154- const paths = Object . keys ( window . objectPaths ) ;
155- let newMessage = message ;
156- urls . forEach ( ( url ) => {
157- newMessage = newMessage . replaceAll ( url , window . objectUrls [ url ] ) ;
158- if ( newMessage . match ( 'index.html' ) ) {
159- const onLineRegex = / o n l i n e (?< lineNo > .\d ) i n / gm;
160- const lineNoRegex = / i n d e x \. h t m l : (?< lineNo > .\d ) : / gm;
161- const match = onLineRegex . exec ( newMessage ) ;
162- const line = match . groups . lineNo ;
163- const resolvedLine = parseInt ( line , 10 ) - htmlOffset ;
164- newMessage = newMessage . replace (
165- onLineRegex ,
166- `on line ${ resolvedLine } in`
167- ) ;
168- newMessage = newMessage . replace (
169- lineNoRegex ,
170- `index.html:${ resolvedLine } :`
171- ) ;
172- }
173- } ) ;
174- paths . forEach ( ( path ) => {
175- newMessage = newMessage . replaceAll ( path , window . objectPaths [ path ] ) ;
176- } ) ;
177- _report . apply ( window . p5 , [ newMessage , method , color ] ) ;
178- } ;
152+ if ( _report ) {
153+ window . p5 . _report = function resolvedReport ( message , method , color ) {
154+ const urls = Object . keys ( window . objectUrls ) ;
155+ const paths = Object . keys ( window . objectPaths ) ;
156+ let newMessage = message ;
157+ urls . forEach ( ( url ) => {
158+ newMessage = newMessage . replaceAll ( url , window . objectUrls [ url ] ) ;
159+ if ( newMessage . match ( 'index.html' ) ) {
160+ const onLineRegex = / o n l i n e (?< lineNo > .\d ) i n / gm;
161+ const lineNoRegex = / i n d e x \. h t m l : (?< lineNo > .\d ) : / gm;
162+ const match = onLineRegex . exec ( newMessage ) ;
163+ const line = match . groups . lineNo ;
164+ const resolvedLine = parseInt ( line , 10 ) - htmlOffset ;
165+ newMessage = newMessage . replace (
166+ onLineRegex ,
167+ `on line ${ resolvedLine } in`
168+ ) ;
169+ newMessage = newMessage . replace (
170+ lineNoRegex ,
171+ `index.html:${ resolvedLine } :`
172+ ) ;
173+ }
174+ } ) ;
175+ paths . forEach ( ( path ) => {
176+ newMessage = newMessage . replaceAll ( path , window . objectPaths [ path ] ) ;
177+ } ) ;
178+ _report . apply ( window . p5 , [ newMessage , method , color ] ) ;
179+ } ;
180+ }
0 commit comments