mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1326534 - Propagate stacktraces for WebDriver errors; r=automatedtester
When we currently create new WebDriver errors we throw away the stacktrace generated by `WebDriverError`'s prototype, `Error`. This change stores the stacktrace, which will cause it to be serialised and returned to the client. This change is not as valuable as storing the stacktraces of internal errors, but brings symmetry to our error handling and may be useful if only to navigate to the source of an error. MozReview-Commit-ID: LCFMwKxxcTp --HG-- extra : rebase_source : 56947805f29000a64c2daef0fd774ea90330c09e
This commit is contained in:
parent
9a4394f2c5
commit
b2889c31fc
@ -211,7 +211,7 @@ error.fromJson = function (json) {
|
||||
* to propagate.
|
||||
*/
|
||||
this.WebDriverError = function (err) {
|
||||
Error.call(this, err);
|
||||
const proto = Error.call(this, err);
|
||||
this.name = "WebDriverError";
|
||||
this.status = "webdriver error";
|
||||
|
||||
@ -220,6 +220,7 @@ this.WebDriverError = function (err) {
|
||||
this.stack = err.stack;
|
||||
} else {
|
||||
this.message = err;
|
||||
this.stack = proto.stack;
|
||||
}
|
||||
};
|
||||
WebDriverError.prototype = Object.create(Error.prototype);
|
||||
|
@ -81,12 +81,15 @@ add_test(function test_toJson() {
|
||||
/Unserialisable error type: [object Error]/);
|
||||
|
||||
let e0 = new WebDriverError();
|
||||
deepEqual({error: e0.status, message: "", stacktrace: ""},
|
||||
error.toJson(e0));
|
||||
let e0s = error.toJson(e0);
|
||||
equal(e0s.error, "webdriver error");
|
||||
equal(e0s.message, "");
|
||||
equal(e0s.stacktrace, e0.stack);
|
||||
|
||||
let e1 = new WebDriverError("a");
|
||||
deepEqual({error: e1.status, message: "a", stacktrace: ""},
|
||||
error.toJson(e1));
|
||||
let e1s = error.toJson(e1);
|
||||
equal(e1s.message, e1.message);
|
||||
equal(e1s.stacktrace, e1.stack);
|
||||
|
||||
let e2 = new JavaScriptError("first", "second", "third", "fourth");
|
||||
let e2s = error.toJson(e2);
|
||||
@ -107,10 +110,17 @@ add_test(function test_fromJson() {
|
||||
Assert.throws(() => error.fromJson({}),
|
||||
/Undeserialisable error type: undefined/);
|
||||
|
||||
// stacks will be different
|
||||
let e1 = new WebDriverError("1");
|
||||
deepEqual(e1, error.fromJson({error: "webdriver error", message: "1"}));
|
||||
let e1r = error.fromJson({error: "webdriver error", message: "1"});
|
||||
equal(e1r.status, e1.status);
|
||||
equal(e1r.message, e1.message);
|
||||
|
||||
// stacks will be different
|
||||
let e2 = new InvalidArgumentError("2");
|
||||
deepEqual(e2, error.fromJson({error: "invalid argument", message: "2"}));
|
||||
let e2r = error.fromJson({error: "invalid argument", message: "2"});
|
||||
equal(e2r.status, e2.status);
|
||||
equal(e2r.message, e2.message);
|
||||
|
||||
let e3 = new JavaScriptError("first", "second", "third", "fourth");
|
||||
let e3s = error.toJson(e3);
|
||||
|
Loading…
Reference in New Issue
Block a user