fix tprintf catching errors

This commit is contained in:
Olivier Gagnon 2021-11-19 22:58:41 -05:00
parent 983c102123
commit c88dade19a
4 changed files with 8 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -690,6 +690,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
Terminal.print(`${workerScript.scriptRef.filename}: ${str}`); Terminal.print(`${workerScript.scriptRef.filename}: ${str}`);
}, },
tprintf: function (format: any, ...args: any): any { tprintf: function (format: any, ...args: any): any {
if (typeof format !== "string") {
throw makeRuntimeErrorMsg("tprintf", "First argument must be string for the format.");
}
const str = vsprintf(format, args); const str = vsprintf(format, args);
if (str.startsWith("ERROR") || str.startsWith("FAIL")) { if (str.startsWith("ERROR") || str.startsWith("FAIL")) {

@ -3664,9 +3664,10 @@ export interface NS extends Singularity {
* @remarks * @remarks
* RAM cost: 0 GB * RAM cost: 0 GB
* *
* @param format - format of the message
* @param msg - Value to be printed. * @param msg - Value to be printed.
*/ */
tprintf(msg: any): void; tprintf(format: string, ...values: any[]): void;
/** /**
* Clears the scripts logs. * Clears the scripts logs.