Bug 804849 - When logging nsresult values, convert to a human-readable string representation. r=Mossop
authorBlair McBride <bmcbride@mozilla.com>
Fri, 26 Oct 2012 14:48:28 +1300
changeset 111637 3e9ca49bd35f7e1101a4ee2f9ce04d98ff341a86
parent 111636 6169f0ad125b981662f9572c0e08e597ededaf8d
child 111638 3380c067c0c6d7cd886fb4087c992db0a9559958
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersMossop
bugs804849
milestone19.0a1
Bug 804849 - When logging nsresult values, convert to a human-readable string representation. r=Mossop
toolkit/mozapps/extensions/AddonLogging.jsm
--- a/toolkit/mozapps/extensions/AddonLogging.jsm
+++ b/toolkit/mozapps/extensions/AddonLogging.jsm
@@ -20,37 +20,43 @@ Components.utils.import("resource://gre/
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 var EXPORTED_SYMBOLS = [ "LogManager" ];
 
 var gDebugLogEnabled = false;
 
 function formatLogMessage(aType, aName, aStr, aException) {
   let message = aType.toUpperCase() + " " + aName + ": " + aStr;
-  if (aException)
-    return message + ": " + aException;
+  if (aException) {
+    if (typeof aException == "number")
+      return message + ": " + Components.Exception("", aException).name
+    else
+      return message + ": " + aException;
+  }
   return message;
 }
 
 function getStackDetails(aException) {
   // Defensively wrap all this to ensure that failing to get the message source
   // doesn't stop the message from being logged
   try {
     if (aException) {
       if (aException instanceof Ci.nsIException) {
         return {
           sourceName: aException.filename,
           lineNumber: aException.lineNumber
         };
       }
 
-      return {
-        sourceName: aException.fileName,
-        lineNumber: aException.lineNumber
-      };
+      if (typeof aException == "object") {
+        return {
+          sourceName: aException.fileName,
+          lineNumber: aException.lineNumber
+        };
+      }
     }
 
     let stackFrame = Components.stack.caller.caller.caller;
     return {
       sourceName: stackFrame.filename,
       lineNumber: stackFrame.lineNumber
     };
   }