Bug 1336214 - Remove duplicate error.wrap. r=maja_zf, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 09 Feb 2017 19:28:30 +0000
changeset 355234 0dd199ef6823dc12ae35edfefcd1a18a48c5be0a
parent 355233 f48f562cf64dfc117719b8f2528713a9480d3260
child 355235 bc051001a42a12c34b0a84fe4d5e020e41c65512
push id6913
push userryanvm@gmail.com
push dateWed, 01 Mar 2017 21:46:21 +0000
treeherdermozilla-esr52@eb22d060c7ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1336214
milestone52.0
Bug 1336214 - Remove duplicate error.wrap. r=maja_zf, a=test-only MozReview-Commit-ID: KC6ByTiyhre
testing/marionette/error.js
testing/marionette/test_error.js
--- a/testing/marionette/error.js
+++ b/testing/marionette/error.js
@@ -76,35 +76,24 @@ error.isError = function (val) {
  * Checks if obj is an object in the WebDriverError prototypal chain.
  */
 error.isWebDriverError = function (obj) {
   return error.isError(obj) &&
       ("name" in obj && ERRORS.has(obj.name));
 };
 
 /**
- * Wraps an Error prototype in a WebDriverError.  If the given error is
- * already a WebDriverError, this is effectively a no-op.
- */
-error.wrap = function (err) {
-  if (error.isWebDriverError(err)) {
-    return err;
-  }
-  return new WebDriverError(`${err.name}: ${err.message}`, err.stack);
-};
-
-/**
  * Wraps an Error as a WebDriverError type.  If the given error is already
  * in the WebDriverError prototype chain, this function acts as a no-op.
  */
 error.wrap = function (err) {
   if (error.isWebDriverError(err)) {
     return err;
   }
-  return new WebDriverError(err.message, err.stacktrace);
+  return new WebDriverError(`${err.name}: ${err.message}`, err.stacktrace);
 };
 
 /**
  * Unhandled error reporter.  Dumps the error and its stacktrace to console,
  * and reports error to the Browser Console.
  */
 error.report = function (err) {
   let msg = `Marionette threw an error: ${error.stringify(err)}`;
--- a/testing/marionette/test_error.js
+++ b/testing/marionette/test_error.js
@@ -43,27 +43,39 @@ add_test(function test_isWebDriverError(
 
   ok(error.isWebDriverError(new WebDriverError()));
   ok(error.isWebDriverError(new InvalidArgumentError()));
 
   run_next_test();
 });
 
 add_test(function test_wrap() {
+  // webdriver-derived errors should not be wrapped
   equal(error.wrap(new WebDriverError()).name, "WebDriverError");
+  ok(error.wrap(new WebDriverError()) instanceof WebDriverError);
   equal(error.wrap(new InvalidArgumentError()).name, "InvalidArgumentError");
+  ok(error.wrap(new InvalidArgumentError()) instanceof WebDriverError);
+  ok(error.wrap(new InvalidArgumentError()) instanceof InvalidArgumentError);
+
+  // JS errors should be wrapped in WebDriverError
   equal(error.wrap(new Error()).name, "WebDriverError");
+  ok(error.wrap(new Error()) instanceof WebDriverError);
   equal(error.wrap(new EvalError()).name, "WebDriverError");
   equal(error.wrap(new InternalError()).name, "WebDriverError");
   equal(error.wrap(new RangeError()).name, "WebDriverError");
   equal(error.wrap(new ReferenceError()).name, "WebDriverError");
   equal(error.wrap(new SyntaxError()).name, "WebDriverError");
   equal(error.wrap(new TypeError()).name, "WebDriverError");
   equal(error.wrap(new URIError()).name, "WebDriverError");
 
+  // wrapped JS errors should retain their type
+  // as part of the message field
+  equal(error.wrap(new WebDriverError("foo")).message, "foo");
+  equal(error.wrap(new TypeError("foo")).message, "TypeError: foo");
+
   run_next_test();
 });
 
 add_test(function test_stringify() {
   equal("<unprintable error>", error.stringify());
   equal("<unprintable error>", error.stringify("foo"));
   equal("[object Object]", error.stringify({}));
   equal("[object Object]\nfoo", error.stringify({stack: "foo"}));