mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-27 16:37:33 +01:00
fix uncaught promise
This commit is contained in:
parent
5dc9ac040a
commit
e9886cc6bc
@ -126,6 +126,7 @@ function startNetscript2Script(workerScript: WorkerScript): Promise<WorkerScript
|
||||
})
|
||||
.catch((e) => reject(e));
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
if (e instanceof Error) {
|
||||
if (e instanceof SyntaxError) {
|
||||
workerScript.errorMessage = makeRuntimeRejectMsg(workerScript, e.message + " (sorry we can't be more helpful)");
|
||||
|
18
src/UncaughtPromiseHandler.ts
Normal file
18
src/UncaughtPromiseHandler.ts
Normal file
@ -0,0 +1,18 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
@ -46,6 +46,7 @@ import { exceptionAlert } from "./utils/helpers/exceptionAlert";
|
||||
import { startExploits } from "./Exploits/loops";
|
||||
|
||||
import React from "react";
|
||||
import { setupUncaughtPromiseHandler } from "./UncaughtPromiseHandler";
|
||||
|
||||
const Engine: {
|
||||
_lastUpdate: number;
|
||||
@ -237,6 +238,7 @@ const Engine: {
|
||||
|
||||
load: function (saveString) {
|
||||
startExploits();
|
||||
setupUncaughtPromiseHandler();
|
||||
// Load game from save or create new game
|
||||
if (loadGame(saveString)) {
|
||||
ThemeEvents.emit();
|
||||
|
Loading…
Reference in New Issue
Block a user