@@ -75,22 +75,17 @@ function getScriptOff(line) {
75
75
return [ line - l , file ] ;
76
76
}
77
77
// catch reference errors, via http://stackoverflow.com/a/12747364/2994108
78
- window . onerror = function onError ( msg , url , lineNumber , columnNo , error ) {
79
- // var string = msg.toLowerCase();
80
- // var substring = "script error";
81
- let data = { } ;
82
- let fileInfo ;
83
- if ( url . match ( EXTERNAL_LINK_REGEX ) !== null && error . stack ) {
84
- const errorNum = error . stack . split ( 'about:srcdoc:' ) [ 1 ] . split ( ':' ) [ 0 ] ;
85
- fileInfo = getScriptOff ( errorNum ) ;
86
- data = `${ msg } (${ fileInfo [ 1 ] } : line ${ fileInfo [ 0 ] } )` ;
87
- } else {
88
- fileInfo = getScriptOff ( lineNumber ) ;
89
- data = `${ msg } (${ fileInfo [ 1 ] } : line ${ fileInfo [ 0 ] } )` ;
90
- }
78
+ window . onerror = function onError ( msg , source , lineNumber , columnNo , error ) {
79
+ const urls = Object . keys ( window . objectUrls ) ;
80
+ let data = '' ;
81
+ urls . forEach ( ( url ) => {
82
+ if ( error . stack . match ( url ) ) {
83
+ data = error . stack . replaceAll ( url , window . objectUrls [ url ] ) ;
84
+ }
85
+ } ) ;
91
86
editor . postMessage (
92
87
{
93
- source : fileInfo [ 1 ] ,
88
+ source : 'sketch' ,
94
89
messages : [
95
90
{
96
91
log : [
@@ -110,12 +105,16 @@ window.onerror = function onError(msg, url, lineNumber, columnNo, error) {
110
105
// catch rejected promises
111
106
window . onunhandledrejection = function onUnhandledRejection ( event ) {
112
107
if ( event . reason && event . reason . message && event . reason . stack ) {
113
- const errorNum = event . reason . stack . split ( 'about:srcdoc:' ) [ 1 ] . split ( ':' ) [ 0 ] ;
114
- const fileInfo = getScriptOff ( errorNum ) ;
115
- const data = `${ event . reason . message } (${ fileInfo [ 1 ] } : line ${ fileInfo [ 0 ] } )` ;
108
+ const urls = Object . keys ( window . objectUrls ) ;
109
+ let data = '' ;
110
+ urls . forEach ( ( url ) => {
111
+ if ( event . reason . stack . match ( url ) ) {
112
+ data = event . reason . stack . replaceAll ( url , window . objectUrls [ url ] ) ;
113
+ }
114
+ } ) ;
116
115
editor . postMessage (
117
116
{
118
- source : fileInfo [ 1 ] ,
117
+ source : 'sketch' ,
119
118
messages : [
120
119
{
121
120
log : [
@@ -132,3 +131,18 @@ window.onunhandledrejection = function onUnhandledRejection(event) {
132
131
) ;
133
132
}
134
133
} ;
134
+
135
+ // Monkeypatch p5._friendlyError
136
+ // const friendlyError = window.p5._friendlyError;
137
+ // window.p5._friendlyError = function (message, method, color) {
138
+ // const urls = Object.keys(window.objectUrls);
139
+ // const paths = Object.keys(window.objectPaths);
140
+ // let newMessage = message;
141
+ // urls.forEach((url) => {
142
+ // newMessage = newMessage.replaceAll(url, window.objectUrls[url]);
143
+ // });
144
+ // paths.forEach((path) => {
145
+ // newMessage = newMessage.replaceAll(path, window.objectPaths[path]);
146
+ // });
147
+ // friendlyError.apply(window.p5, [newMessage, method, color]);
148
+ // };
0 commit comments