From 6661473adc674211084fbb839e99b8de367f7d47 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sat, 12 Jun 2021 05:09:12 -0400 Subject: [PATCH] Fix an issue where an empty stack trace would appear in ns1 scripts --- src/NetscriptFunctions.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index f8b74fe16..486b0ddc0 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -376,7 +376,7 @@ function NetscriptFunctions(workerScript) { const makeRuntimeErrorMsg = function(caller, msg) { const stack = (new Error()).stack.split('\n').slice(1); const scripts = workerScript.getServer().scripts; - let userstack = []; + const userstack = []; for(const stackline of stack) { let filename; for(const script of scripts) { @@ -398,13 +398,12 @@ function NetscriptFunctions(workerScript) { const lineMatch = line.match(lineRe); const funcMatch = line.match(funcRe); if(lineMatch && funcMatch) { - let func = funcMatch[1]; - return {line: lineMatch[1], func: func}; + return {line: lineMatch[1], func: funcMatch[1]}; } return null; } let call = {line: "-1", func: "unknown"}; - let chromeCall = parseChromeStackline(stackline); + const chromeCall = parseChromeStackline(stackline); if (chromeCall) { call = chromeCall; } @@ -430,7 +429,8 @@ function NetscriptFunctions(workerScript) { } workerScript.log(caller, msg); - const rejectMsg = `${caller}: ${msg}

Stack:
${userstack.join('
')}` + let rejectMsg = `${caller}: ${msg}` + if(userstack.length !== 0) rejectMsg += `

Stack:
${userstack.join('
')}`; return makeRuntimeRejectMsg(workerScript, rejectMsg); }