Bug 906795 - safeErrorString should include a stack; r=vporof

This commit is contained in:
Nick Fitzgerald
2013-08-20 11:15:11 -07:00
parent 62c5f7e826
commit c8d2d94d9c
7 changed files with 130 additions and 8 deletions

View File

@@ -6,12 +6,26 @@
/* General utilities used throughout devtools. */
/* Turn the error e into a string, without fail. */
/**
* Turn the error |aError| into a string, without fail.
*/
this.safeErrorString = function safeErrorString(aError) {
try {
var s = aError.toString();
if (typeof s === "string")
return s;
let errorString = aError.toString();
if (typeof errorString === "string") {
// Attempt to attach a stack to |errorString|. If it throws an error, or
// isn't a string, don't use it.
try {
if (aError.stack) {
let stack = aError.stack.toString();
if (typeof stack === "string") {
errorString += "\nStack: " + stack;
}
}
} catch (ee) { }
return errorString;
}
} catch (ee) { }
return "<failed trying to find error description>";
@@ -22,9 +36,6 @@ this.safeErrorString = function safeErrorString(aError) {
*/
this.reportException = function reportException(aWho, aException) {
let msg = aWho + " threw an exception: " + safeErrorString(aException);
if (aException.stack) {
msg += "\nCall stack:\n" + aException.stack;
}
dump(msg + "\n");