mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 00:32:51 +02:00
SCRIPTS: Script modules are reused when they are imported (#461)
Also corrects some compile race conditions.
This commit is contained in:
@@ -234,8 +234,8 @@ function argsToString(args: unknown[]): string {
|
||||
/** Creates an error message string containing hostname, scriptname, and the error message msg */
|
||||
function makeBasicErrorMsg(ws: WorkerScript | ScriptDeath, msg: string, type = "RUNTIME"): string {
|
||||
if (ws instanceof WorkerScript) {
|
||||
for (const scriptUrl of ws.scriptRef.dependencies) {
|
||||
msg = msg.replace(new RegExp(scriptUrl.url, "g"), scriptUrl.filename);
|
||||
for (const [scriptUrl, script] of ws.scriptRef.dependencies) {
|
||||
msg = msg.replace(new RegExp(scriptUrl, "g"), script.filename);
|
||||
}
|
||||
}
|
||||
return `${type} ERROR\n${ws.name}@${ws.hostname} (PID - ${ws.pid})\n\n${msg}`;
|
||||
@@ -248,20 +248,19 @@ function makeRuntimeErrorMsg(ctx: NetscriptContext, msg: string, type = "RUNTIME
|
||||
const stack = errstack.split("\n").slice(1);
|
||||
const ws = ctx.workerScript;
|
||||
const caller = ctx.functionPath;
|
||||
const scripts = ws.getServer().scripts;
|
||||
const userstack = [];
|
||||
for (const stackline of stack) {
|
||||
let filename;
|
||||
for (const script of scripts) {
|
||||
if (script.filename && stackline.includes(script.filename)) {
|
||||
filename = script.filename;
|
||||
const filename = (() => {
|
||||
// Filename is current file if url found
|
||||
if (ws.scriptRef.url && stackline.includes(ws.scriptRef.url)) return ws.scriptRef.filename;
|
||||
// Also check urls for dependencies
|
||||
for (const [url, script] of ws.scriptRef.dependencies) if (stackline.includes(url)) return script.filename;
|
||||
// Check for filenames directly if no URL found
|
||||
if (stackline.includes(ws.scriptRef.filename)) return ws.scriptRef.filename;
|
||||
for (const script of ws.scriptRef.dependencies.values()) {
|
||||
if (stackline.includes(script.filename)) return script.filename;
|
||||
}
|
||||
for (const dependency of script.dependencies) {
|
||||
if (stackline.includes(dependency.filename)) {
|
||||
filename = dependency.filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
if (!filename) continue;
|
||||
|
||||
interface ILine {
|
||||
|
||||
Reference in New Issue
Block a user