Bug 1275042 - Turn undefined error message- and stacktrace fields into strings; r?automatedtester
MozReview-Commit-ID: A2DYgTqp2rp
--- a/testing/marionette/error.js
+++ b/testing/marionette/error.js
@@ -135,18 +135,18 @@ error.stringify = function(err) {
*/
error.toJson = function(err) {
if (!error.isWebDriverError(err)) {
throw new TypeError(`Unserialisable error type: ${err}`);
}
let json = {
error: err.status,
- message: err.message || null,
- stacktrace: err.stack || null,
+ message: err.message || "",
+ stacktrace: err.stack || "",
};
return json;
};
/**
* Unmarshal a JSON dictionary to a WebDriverError prototype.
*
* @param {Object.<string, string>} json
--- a/testing/marionette/test_error.js
+++ b/testing/marionette/test_error.js
@@ -88,18 +88,22 @@ add_test(function test_stringify() {
run_next_test();
});
add_test(function test_toJson() {
Assert.throws(() => error.toJson(new Error()),
/Unserialisable error type: [object Error]/);
+ let e0 = new WebDriverError();
+ deepEqual({error: e0.status, message: "", stacktrace: ""},
+ error.toJson(e0));
+
let e1 = new WebDriverError("a");
- deepEqual({error: e1.status, message: "a", stacktrace: null},
+ deepEqual({error: e1.status, message: "a", stacktrace: ""},
error.toJson(e1));
let e2 = new JavaScriptError("first", "second", "third", "fourth");
let e2s = error.toJson(e2);
equal(e2.status, e2s.error);
equal(e2.message, e2s.message);
ok(e2s.stacktrace.match(/second/));
ok(e2s.stacktrace.match(/third/));