2022-02-06 01:15:42 +01:00
|
|
|
import { ScriptDeath } from "./Netscript/ScriptDeath";
|
2021-12-20 19:57:07 +01:00
|
|
|
import { isScriptErrorMessage } from "./NetscriptEvaluator";
|
|
|
|
import { dialogBoxCreate } from "./ui/React/DialogBox";
|
|
|
|
|
|
|
|
export function setupUncaughtPromiseHandler(): void {
|
|
|
|
window.addEventListener("unhandledrejection", function (e) {
|
|
|
|
if (isScriptErrorMessage(e.reason)) {
|
|
|
|
const errorTextArray = e.reason.split("|DELIMITER|");
|
|
|
|
const hostname = errorTextArray[1];
|
|
|
|
const scriptName = errorTextArray[2];
|
|
|
|
const errorMsg = errorTextArray[3];
|
|
|
|
|
|
|
|
let msg = `UNCAUGHT PROMISE ERROR<br>You forgot to await a promise<br>${scriptName}@${hostname}<br>`;
|
|
|
|
msg += "<br>";
|
|
|
|
msg += errorMsg;
|
|
|
|
dialogBoxCreate(msg);
|
2022-02-06 01:15:42 +01:00
|
|
|
} else if (e.reason instanceof ScriptDeath) {
|
2021-12-20 22:06:19 +01:00
|
|
|
const msg =
|
2022-02-06 01:15:42 +01:00
|
|
|
`UNCAUGHT PROMISE ERROR<br>You forgot to await a promise<br>${e.reason.name}@${e.reason.hostname} (PID - ${e.reason.pid})<br>` +
|
2021-12-20 22:06:19 +01:00
|
|
|
`Maybe hack / grow / weaken ?`;
|
|
|
|
dialogBoxCreate(msg);
|
2021-12-20 19:57:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|