Bug 1263747 - Log error messages when stringifying errors. r=bgrins

MozReview-Commit-ID: 2MB8IDKfVHo

--HG--
extra : rebase_source : d7922cf9a5c1dc37283299aa97c4b596fb0b68bd
This commit is contained in:
Kit Cambridge 2016-04-11 14:51:33 -07:00
parent 6ad68f4d61
commit f206eaee71
2 changed files with 21 additions and 4 deletions

View File

@ -1073,7 +1073,7 @@ this.PushService = {
Services.telemetry.getHistogramById("PUSH_API_SUBSCRIBE_FAILED").add()
if (!reply.error) {
console.warn("onRegisterError: Called without valid error message!",
reply, String(reply));
reply);
throw new Error("Registration error");
}
throw reply.error;

View File

@ -105,6 +105,21 @@ function getCtorName(aObj) {
return Object.prototype.toString.call(aObj).slice(8, -1);
}
/**
* Indicates whether an object is a JS or `Components.Exception` error.
*
* @param {object} aThing
The object to check
* @return {boolean}
Is this object an error?
*/
function isError(aThing) {
return aThing && (
(typeof aThing.name == "string" &&
aThing.name.startsWith("NS_ERROR_")) ||
getCtorName(aThing).endsWith("Error"));
}
/**
* A single line stringification of an object designed for use by humans
*
@ -124,6 +139,10 @@ function stringify(aThing, aAllowNewLines) {
return "null";
}
if (isError(aThing)) {
return "Message: " + aThing;
}
if (typeof aThing == "object") {
let type = getCtorName(aThing);
if (aThing instanceof Components.interfaces.nsIDOMNode && aThing.tagName) {
@ -203,9 +222,7 @@ function log(aThing) {
i++;
}
}
else if (type.match("Error$") ||
(typeof aThing.name == "string" &&
aThing.name.match("NS_ERROR_"))) {
else if (isError(aThing)) {
reply += " Message: " + aThing + "\n";
if (aThing.stack) {
reply += " Stack:\n";