Improved script error print

canary
WolverinDEV 2020-08-21 00:12:45 +02:00
parent 754ec6b3ab
commit e047e08622
1 changed files with 9 additions and 6 deletions

View File

@ -107,6 +107,8 @@ export async function load_multiple(paths: SourcePath[], options: MultipleOption
let prefix = ""; let prefix = "";
while(prefix.length < sname.length + 7) prefix += " "; while(prefix.length < sname.length + 7) prefix += " ";
console.log(" - %s: %s:\n%s", sname, source.message, source.stack.split("\n").map(e => prefix + e.trim()).slice(1).join("\n")); console.log(" - %s: %s:\n%s", sname, source.message, source.stack.split("\n").map(e => prefix + e.trim()).slice(1).join("\n"));
} else if(typeof source === "string") {
console.log(" - %s: %s", sname, source);
} else { } else {
console.log(" - %s: %o", sname, source); console.log(" - %s: %o", sname, source);
} }
@ -116,18 +118,19 @@ export async function load_multiple(paths: SourcePath[], options: MultipleOption
} }
} }
let errorMessage;
{ {
const error = result.failed[0].error; const error = result.failed[0].error;
console.error(error); if(error instanceof LoadSyntaxError) {
let errorMessage;
if(error instanceof LoadSyntaxError)
errorMessage = error.source.message; errorMessage = error.source.message;
else if(typeof error === "string") } else if(typeof error === "string") {
errorMessage = error; errorMessage = error;
else } else {
console.error("Script %s loading error: %o", script_name(result.failed[0].request, false), error);
errorMessage = "View the browser console for more information!"; errorMessage = "View the browser console for more information!";
}
critical_error("Failed to load script " + script_name(result.failed[0].request, true), errorMessage); critical_error("Failed to load script " + script_name(result.failed[0].request, true), errorMessage);
} }
throw "failed to load script " + script_name(result.failed[0].request, false); throw "failed to load script " + script_name(result.failed[0].request, false) + " (" + errorMessage + ")";
} }
} }