log stringified exceptions in debug output

If an exception (e.g. Zotero.Exception.UnloadedDataException)
is thrown without the debugger enabled (meaning, by most
users), it is logged as a non-descriptive
[JavaScript Error: "uncaught exception: Object"].

This stringifies the exception object and puts the
string into the message, so that the actual error and the
stacktrace are not lost.
This commit is contained in:
Bogdan Abaev 2025-03-26 17:07:59 -07:00
parent b3a3757716
commit d4155488e1

View file

@ -1373,7 +1373,12 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
}
if (asStrings) {
errors.push(altMessage || msg.message)
let message = altMessage || msg.message;
// Stringify exceptions object instead of just returning "Object"
if (message.includes('uncaught exception: Object') && typeof msg.exception == "object") {
message = "[JavaScript Error:" + JSON.stringify(msg.exception);
}
errors.push(message);
}
else {
errors.push(msg);