Bug 851209 - Make exceptionStr robust against null exceptions. r=gps
authorRichard Newman <rnewman@mozilla.com>
Thu, 14 Mar 2013 11:23:47 -0700
changeset 124791 7036707114197511489a9e080bcc41f3ed10c07e
parent 124653 b672877ed04656a9f4041f31ef5d8030df662726
child 124792 9db3cfddc9be4fd5821644b8c0e05baa366c067f
push id24435
push userrnewman@mozilla.com
push dateThu, 14 Mar 2013 22:31:19 +0000
treeherdermozilla-central@0f7261e288f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs851209
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 851209 - Make exceptionStr robust against null exceptions. r=gps
services/common/tests/unit/test_utils_exceptionStr.js
services/common/tests/unit/xpcshell.ini
services/common/utils.js
new file mode 100644
--- /dev/null
+++ b/services/common/tests/unit/test_utils_exceptionStr.js
@@ -0,0 +1,17 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+function run_test() {
+  run_next_test();
+}
+
+add_test(function test_exceptionStr_non_exceptions() {
+  do_check_eq(CommonUtils.exceptionStr(null), "null");
+  do_check_eq(CommonUtils.exceptionStr(false), "false");
+  do_check_eq(CommonUtils.exceptionStr(undefined), "undefined");
+  do_check_eq(CommonUtils.exceptionStr(12), "12 No traceback available");
+
+  run_next_test();
+});
--- a/services/common/tests/unit/xpcshell.ini
+++ b/services/common/tests/unit/xpcshell.ini
@@ -8,16 +8,17 @@ firefox-appdir = browser
 
 [test_utils_atob.js]
 [test_utils_convert_string.js]
 [test_utils_dateprefs.js]
 [test_utils_deepCopy.js]
 [test_utils_encodeBase32.js]
 [test_utils_encodeBase64URL.js]
 [test_utils_ensureMillisecondsTimestamp.js]
+[test_utils_exceptionStr.js]
 [test_utils_json.js]
 [test_utils_makeURI.js]
 [test_utils_namedTimer.js]
 [test_utils_stackTrace.js]
 [test_utils_utf8.js]
 [test_utils_uuid.js]
 
 [test_async_chain.js]
--- a/services/common/utils.js
+++ b/services/common/utils.js
@@ -8,16 +8,19 @@ this.EXPORTED_SYMBOLS = ["CommonUtils"];
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/osfile.jsm")
 Cu.import("resource://services-common/log4moz.js");
 
 this.CommonUtils = {
   exceptionStr: function exceptionStr(e) {
+    if (!e) {
+      return "" + e;
+    }
     let message = e.message ? e.message : e;
     return message + " " + CommonUtils.stackTrace(e);
   },
 
   stackTrace: function stackTrace(e) {
     // Wrapped nsIException
     if (e.location) {
       let frame = e.location;