зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
9a4394f2c5
Коммит
b2889c31fc
|
@ -211,7 +211,7 @@ error.fromJson = function (json) {
|
||||||
* to propagate.
|
* to propagate.
|
||||||
*/
|
*/
|
||||||
this.WebDriverError = function (err) {
|
this.WebDriverError = function (err) {
|
||||||
Error.call(this, err);
|
const proto = Error.call(this, err);
|
||||||
this.name = "WebDriverError";
|
this.name = "WebDriverError";
|
||||||
this.status = "webdriver error";
|
this.status = "webdriver error";
|
||||||
|
|
||||||
|
@ -220,6 +220,7 @@ this.WebDriverError = function (err) {
|
||||||
this.stack = err.stack;
|
this.stack = err.stack;
|
||||||
} else {
|
} else {
|
||||||
this.message = err;
|
this.message = err;
|
||||||
|
this.stack = proto.stack;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
WebDriverError.prototype = Object.create(Error.prototype);
|
WebDriverError.prototype = Object.create(Error.prototype);
|
||||||
|
|
|
@ -81,12 +81,15 @@ add_test(function test_toJson() {
|
||||||
/Unserialisable error type: [object Error]/);
|
/Unserialisable error type: [object Error]/);
|
||||||
|
|
||||||
let e0 = new WebDriverError();
|
let e0 = new WebDriverError();
|
||||||
deepEqual({error: e0.status, message: "", stacktrace: ""},
|
let e0s = error.toJson(e0);
|
||||||
error.toJson(e0));
|
equal(e0s.error, "webdriver error");
|
||||||
|
equal(e0s.message, "");
|
||||||
|
equal(e0s.stacktrace, e0.stack);
|
||||||
|
|
||||||
let e1 = new WebDriverError("a");
|
let e1 = new WebDriverError("a");
|
||||||
deepEqual({error: e1.status, message: "a", stacktrace: ""},
|
let e1s = error.toJson(e1);
|
||||||
error.toJson(e1));
|
equal(e1s.message, e1.message);
|
||||||
|
equal(e1s.stacktrace, e1.stack);
|
||||||
|
|
||||||
let e2 = new JavaScriptError("first", "second", "third", "fourth");
|
let e2 = new JavaScriptError("first", "second", "third", "fourth");
|
||||||
let e2s = error.toJson(e2);
|
let e2s = error.toJson(e2);
|
||||||
|
@ -107,10 +110,17 @@ add_test(function test_fromJson() {
|
||||||
Assert.throws(() => error.fromJson({}),
|
Assert.throws(() => error.fromJson({}),
|
||||||
/Undeserialisable error type: undefined/);
|
/Undeserialisable error type: undefined/);
|
||||||
|
|
||||||
|
// stacks will be different
|
||||||
let e1 = new WebDriverError("1");
|
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");
|
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 e3 = new JavaScriptError("first", "second", "third", "fourth");
|
||||||
let e3s = error.toJson(e3);
|
let e3s = error.toJson(e3);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче