From 0c358c588e9732ed225f012898fa6602e7a0a110 Mon Sep 17 00:00:00 2001 From: Snarling <84951833+Snarling@users.noreply.github.com> Date: Tue, 16 Aug 2022 20:16:57 -0400 Subject: [PATCH] ns.atExit errors more readable, allows ns functions --- src/Netscript/killWorkerScript.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Netscript/killWorkerScript.ts b/src/Netscript/killWorkerScript.ts index 70b716a7a..af45b3988 100644 --- a/src/Netscript/killWorkerScript.ts +++ b/src/Netscript/killWorkerScript.ts @@ -52,22 +52,24 @@ function killWorkerScriptByPid(pid: number): boolean { return false; } -function stopAndCleanUpWorkerScript(workerScript: WorkerScript): void { - if (typeof workerScript.atExit === "function") { +function stopAndCleanUpWorkerScript(ws: WorkerScript): void { + killNetscriptDelay(ws); + if (typeof ws.atExit === "function") { try { - workerScript.atExit(); + ws.env.stopFlag = false; + ws.atExit(); } catch (e: unknown) { + let message = e instanceof ScriptDeath ? e.errorMessage : String(e); + message = message.replace(/.*\|DELIMITER\|/, ""); dialogBoxCreate( - `Error trying to call atExit for script ${workerScript.name} on ${workerScript.hostname} ${ - workerScript.scriptRef.args - } ${String(e)}`, + `Error trying to call atExit for script ${ws.name} on ${ws.hostname} ${ws.scriptRef.args}\n` + message, ); + console.log(e); } - workerScript.atExit = undefined; + ws.atExit = undefined; } - workerScript.env.stopFlag = true; - killNetscriptDelay(workerScript); - removeWorkerScript(workerScript); + ws.env.stopFlag = true; + removeWorkerScript(ws); } /**