BUGFIX: Error message shows blob URL instead of script name (#2265)

This commit is contained in:
catloversg
2025-07-24 04:30:25 +07:00
committed by GitHub
parent 7019145f3b
commit ff106bb764
4 changed files with 27 additions and 35 deletions
+10 -8
View File
@@ -1,5 +1,4 @@
import type { WorkerScript } from "./WorkerScript";
import { ScriptDeath } from "./ScriptDeath";
import type { NetscriptContext } from "./APIWrapper";
/** Log a message to a script's logs */
@@ -7,14 +6,17 @@ export function log(ctx: NetscriptContext, message: () => string) {
ctx.workerScript.log(ctx.functionPath, message);
}
/** Creates an error message string containing hostname, scriptname, and the error message msg */
export function basicErrorMessage(ws: WorkerScript | ScriptDeath, msg: string, type = "RUNTIME"): string {
if (!(ws instanceof ScriptDeath)) {
for (const [scriptUrl, script] of ws.scriptRef.dependencies) {
msg = msg.replace(new RegExp(scriptUrl, "g"), script.filename);
}
/** Error messages may contain blob URLs (). This function replaces those URLs with the script names. */
export function parseBlobUrlInMessage(ws: WorkerScript, msg: string): string {
for (const [scriptUrl, script] of ws.scriptRef.dependencies) {
msg = msg.replaceAll(scriptUrl, script.filename);
}
return `${type} ERROR\n${ws.name}@${ws.hostname} (PID - ${ws.pid})\n\n${msg}`;
return msg;
}
/** Creates an error message string containing hostname, scriptname, and the error message msg */
export function basicErrorMessage(ws: WorkerScript, msg: string, type = "RUNTIME"): string {
return `${type} ERROR\n${ws.name}@${ws.hostname} (PID - ${ws.pid})\n\n${parseBlobUrlInMessage(ws, msg)}`;
}
/**
+1 -2
View File
@@ -55,7 +55,7 @@ import { resolveFilePath, FilePath } from "../Paths/FilePath";
import { hasScriptExtension, ScriptFilePath } from "../Paths/ScriptFilePath";
import { CustomBoundary } from "../ui/Components/CustomBoundary";
import { ServerConstants } from "../Server/data/Constants";
import { basicErrorMessage, errorMessage, log } from "./ErrorMessages";
import { errorMessage, log } from "./ErrorMessages";
import { assertStringWithNSContext, debugType } from "./TypeAssertion";
import {
canAccessBitNodeFeature,
@@ -79,7 +79,6 @@ export const helpers = {
hostReturnOptions,
returnServerID,
argsToString,
basicErrorMessage,
errorMessage,
validateHGWOptions,
checkEnvFlags,