Slightly better error catching..

This commit is contained in:
2023-10-24 23:03:33 +02:00
parent 4f88d0a9bf
commit bb8701a865
3 changed files with 27 additions and 5 deletions

View File

@ -143,10 +143,21 @@ export class UserAPI {
};
_reportError = (error: any): void => {
console.log(error);
const extractLineNumber = (error: Error) => {
const stackLines = error.stack?.split("\n");
if (stackLines && stackLines.length > 1) {
const match = stackLines[1].match(/:(\d+):/);
if (match) return parseInt(match[1], 10);
}
return null;
};
const lineNumber = extractLineNumber(error);
const errorMessage = lineNumber ? `${error.message} (Line: ${lineNumber})` : error.message;
clearTimeout(this.errorTimeoutID);
clearTimeout(this.printTimeoutID);
this.app.interface.error_line.innerHTML = error as string;
this.app.interface.error_line.innerHTML = errorMessage;
this.app.interface.error_line.style.color = "color-red-800";
this.app.interface.error_line.classList.remove("hidden");
this.errorTimeoutID = setTimeout(

View File

@ -25,7 +25,7 @@ const tryCatchWrapper = (
resolve(true);
} catch (error) {
application.interface.error_line.innerHTML = error as string;
console.log(error);
application.api._reportError(error as string)
resolve(false);
}
});
@ -75,7 +75,7 @@ export const tryEvaluate = async (
}
} catch (error) {
application.interface.error_line.innerHTML = error as string;
console.log(error);
application.api._reportError(error as string)
}
};

View File

@ -21,6 +21,9 @@ export const installWindowBehaviors = (
window: Window,
preventMultipleTabs: boolean = false
) => {
window.addEventListener("resize", () =>
handleResize(app.interface.scope as HTMLCanvasElement)
);
@ -42,7 +45,7 @@ export const installWindowBehaviors = (
localStorage.openpages = Date.now();
window.addEventListener(
"storage",
function (e) {
function(e) {
if (e.key == "openpages") {
// Listen if anybody else is opening the same page!
localStorage.page_available = Date.now();
@ -57,4 +60,12 @@ export const installWindowBehaviors = (
false
);
}
window.addEventListener('error', e => {
console.log("Je suis bien installé !")
console.log(e.message
, '\n', e.filename, ':', e.lineno, (e.colno ? ':' + e.colno : '')
, e.error && e.error.stack ? '\n' : '', e.error ? e.error.stack : undefined
);
}, false);
};