Skip to content

Commit ae9f8ce

Browse files
authoredJul 12, 2021
Merge pull request #1898 from processing/bug/fes
Handle if window.p5._report is not defined
2 parents 9e656b5 + c338981 commit ae9f8ce

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed
 

‎client/utils/previewEntry.js

+29-27
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,32 @@ window.onunhandledrejection = async function onUnhandledRejection(event) {
149149

150150
// Monkeypatch p5._friendlyError
151151
const { _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 = /on line (?<lineNo>.\d) in/gm;
160-
const lineNoRegex = /index\.html:(?<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 = /on line (?<lineNo>.\d) in/gm;
161+
const lineNoRegex = /index\.html:(?<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

Comments
 (0)
Please sign in to comment.