diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 96952422f..e7f1b1e6d 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -79,6 +79,7 @@ import { CalculateShareMult, StartSharing } from "./NetworkShare/Share"; import { recentScripts } from "./Netscript/RecentScripts"; import { InternalAPI, NetscriptContext, wrapAPI } from "./Netscript/APIWrapper"; import { INetscriptExtra } from "./NetscriptFunctions/Extra"; +import { ScriptDeath } from "./Netscript/ScriptDeath"; export type NSFull = NS & INetscriptExtra; @@ -833,12 +834,10 @@ const base: InternalAPI = { return scriptsKilled > 0; }, - exit: (ctx: NetscriptContext) => (): void => { - if (killWorkerScript(ctx.workerScript)) { - helpers.log(ctx, () => "Exiting..."); - } else { - helpers.log(ctx, () => "Failed. This is a bug. Report to dev."); - } + exit: (ctx: NetscriptContext) => (): never => { + helpers.log(ctx, () => "Exiting..."); + ctx.workerScript.env.stopFlag = true; + throw new ScriptDeath(ctx.workerScript); }, scp: (ctx: NetscriptContext) => diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index f94f89537..5ae0f9611 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5424,7 +5424,7 @@ export interface NS { * @remarks * RAM cost: 0 GB */ - exit(): void; + exit(): never; /** * Copy file between servers.