Merge pull request #3189 from Master-Guy/issues/2725

dialogBox+stop on NS1 async function throw
This commit is contained in:
hydroflame 2022-03-20 21:27:57 -04:00 committed by GitHub
commit 9eee30170f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

@ -144,7 +144,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
const safeGetServer = function (hostname: string, callingFnName: string): BaseServer { const safeGetServer = function (hostname: string, callingFnName: string): BaseServer {
const server = GetServer(hostname); const server = GetServer(hostname);
if (server == null) { if (server == null) {
throw makeRuntimeErrorMsg(callingFnName, `Invalid hostname or IP: ${hostname}`); throw makeRuntimeErrorMsg(callingFnName, `Invalid hostname: ${hostname}`);
} }
return server; return server;
}; };

@ -178,7 +178,7 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<WorkerScript
const entry = ns[name]; const entry = ns[name];
if (typeof entry === "function") { if (typeof entry === "function") {
//Async functions need to be wrapped. See JS-Interpreter documentation //Async functions need to be wrapped. See JS-Interpreter documentation
if (["hack", "grow", "weaken", "sleep", "prompt", "manualHack", "scp", "write", "share"].includes(name)) { if (["hack", "grow", "weaken", "sleep", "prompt", "manualHack", "scp", "write", "share", "wget"].includes(name)) {
const tempWrapper = function (...args: any[]): void { const tempWrapper = function (...args: any[]): void {
const fnArgs = []; const fnArgs = [];
@ -199,7 +199,21 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<WorkerScript
}) })
.catch(function (err: any) { .catch(function (err: any) {
// workerscript is when you cancel a delay // workerscript is when you cancel a delay
if (!(err instanceof WorkerScript)) console.error(err); if (!(err instanceof WorkerScript)) {
console.error(err);
const errorTextArray = err.split("|DELIMITER|");
const hostname = errorTextArray[1];
const scriptName = errorTextArray[2];
const errorMsg = errorTextArray[3];
let msg = `${scriptName}@${hostname}<br>`;
msg += "<br>";
msg += errorMsg;
dialogBoxCreate(msg);
workerScript.env.stopFlag = true;
workerScript.running = false;
killWorkerScript(workerScript);
return Promise.resolve(workerScript);
}
}); });
}; };
int.setProperty(scope, name, int.createAsyncFunction(tempWrapper)); int.setProperty(scope, name, int.createAsyncFunction(tempWrapper));