Bug 1441019 - Document Marionette error module. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 26 Feb 2018 11:05:57 +0000
changeset 759875 de1c6aacd047b22d717b16c09c36d4df5fdae1c4
parent 759874 0cbafc0c0fc05dd592dbd5c58e863c1d4597f488
child 759876 80b50aece45e67c982d9a35e92fe1f090d3ef6e7
push id100500
push userbmo:ato@sny.no
push dateMon, 26 Feb 2018 19:31:26 +0000
reviewerswhimboo
bugs1441019
milestone60.0a1
Bug 1441019 - Document Marionette error module. r?whimboo Takes error descriptions from the WebDriver standard and uses them to document error types in Marionette. This will make it possible to generate an internals list of them. MozReview-Commit-ID: EGxWOjOpjBm
testing/marionette/doc/internals/error.rst
testing/marionette/error.js
--- a/testing/marionette/doc/internals/error.rst
+++ b/testing/marionette/doc/internals/error.rst
@@ -1,2 +1,35 @@
 error module
 ============
+
+.. js:autofunction:: error.isError
+.. js:autofunction:: error.isWebDriverError
+.. js:autofunction:: error.wrap
+.. js:autofunction:: error.report
+.. js:autofunction:: error.stringify
+.. js:autofunction:: stack
+
+.. js:autoclass:: ElementClickInterceptedError
+.. js:autoclass:: ElementNotAccessibleError
+.. js:autoclass:: ElementNotInteractableError
+.. js:autoclass:: InsecureCertificateError
+.. js:autoclass:: InvalidArgumentError
+.. js:autoclass:: InvalidCookieDomainError
+.. js:autoclass:: InvalidElementStateError
+.. js:autoclass:: InvalidSelectorError
+.. js:autoclass:: InvalidSessionIDError
+.. js:autoclass:: JavaScriptError
+.. js:autoclass:: MoveTargetOutOfBoundsError
+.. js:autoclass:: NoAlertOpenError
+.. js:autoclass:: NoSuchElementError
+.. js:autoclass:: NoSuchFrameError
+.. js:autoclass:: NoSuchWindowError
+.. js:autoclass:: ScriptTimeoutError
+.. js:autoclass:: SessionNotCreatedError
+.. js:autoclass:: StaleElementReferenceError
+.. js:autoclass:: TimeoutError
+.. js:autoclass:: UnableToSetCookieError
+.. js:autoclass:: UnexpectedAlertOpenError
+.. js:autoclass:: UnknownCommandError
+.. js:autoclass:: UnknownError
+.. js:autoclass:: UnsupportedOperationError
+.. js:autoclass:: WebDriverError
--- a/testing/marionette/error.js
+++ b/testing/marionette/error.js
@@ -49,31 +49,31 @@ this.EXPORTED_SYMBOLS = [
   "error",
   "stack",
 ].concat(Array.from(ERRORS));
 
 /** @namespace */
 this.error = {};
 
 /**
- * Check if |val| is an instance of the |Error| prototype.
+ * Check if ``val`` is an instance of the ``Error`` prototype.
  *
  * Because error objects may originate from different globals, comparing
  * the prototype of the left hand side with the prototype property from
- * the right hand side, which is what |instanceof| does, will not work.
+ * the right hand side, which is what ``instanceof`` does, will not work.
  * If the LHS and RHS come from different globals, this check will always
  * fail because the two objects will not have the same identity.
  *
- * Therefore it is not safe to use |instanceof| in any multi-global
- * situation, e.g. in content across multiple Window objects or anywhere
+ * Therefore it is not safe to use ``instanceof`` in any multi-global
+ * situation, e.g. in content across multiple ``Window`` objects or anywhere
  * in chrome scope.
  *
- * This function also contains a special check if |val| is an XPCOM
- * |nsIException| because they are special snowflakes and may indeed
- * cause Firefox to crash if used with |instanceof|.
+ * This function also contains a special check if ``val`` is an XPCOM
+ * ``nsIException`` because they are special snowflakes and may indeed
+ * cause Firefox to crash if used with ``instanceof``.
  *
  * @param {*} val
  *     Any value that should be undergo the test for errorness.
  * @return {boolean}
  *     True if error, false otherwise.
  */
 error.isError = function(val) {
   if (val === null || typeof val != "object") {
@@ -87,35 +87,43 @@ error.isError = function(val) {
     let proto = Object.getPrototypeOf(val);
     return BUILTIN_ERRORS.has(proto.toString());
   } catch (e) {
     return false;
   }
 };
 
 /**
- * Checks if obj is an object in the WebDriverError prototypal chain.
+ * Checks if ``obj`` is an object in the :js:class:`WebDriverError`
+ * prototypal chain.
+ *
+ * @param {*} obj
+ *     Arbitrary object to test.
+ *
+ * @return {boolean}
+ *     True if ``obj`` is of the WebDriverError prototype chain,
+ *     false otherwise.
  */
 error.isWebDriverError = function(obj) {
   return error.isError(obj) &&
       ("name" in obj && ERRORS.has(obj.name));
 };
 
 /**
- * Ensures error instance is a WebDriverError.
+ * Ensures error instance is a :js:class:`WebDriverError`.
  *
  * If the given error is already in the WebDriverError prototype
- * chain, |err| is returned unmodified.  If it is not, it is wrapped
- * in UnknownError.
+ * chain, ``err`` is returned unmodified.  If it is not, it is wrapped
+ * in :js:class:`UnknownError`.
  *
  * @param {Error} err
  *     Error to conditionally turn into a WebDriverError.
  *
  * @return {WebDriverError}
- *     If |err| is a WebDriverError, it is returned unmodified.
+ *     If ``err`` is a WebDriverError, it is returned unmodified.
  *     Otherwise an UnknownError type is returned.
  */
 error.wrap = function(err) {
   if (error.isWebDriverError(err)) {
     return err;
   }
   return new UnknownError(err);
 };
@@ -294,45 +302,61 @@ class InsecureCertificateError extends W
 /** The arguments passed to a command are either invalid or malformed. */
 class InvalidArgumentError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "invalid argument";
   }
 }
 
+/**
+ * An illegal attempt was made to set a cookie under a different
+ * domain than the current page.
+ */
 class InvalidCookieDomainError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "invalid cookie domain";
   }
 }
 
+/**
+ * A command could not be completed because the element is in an
+ * invalid state, e.g. attempting to clear an element that isn't both
+ * editable and resettable.
+ */
 class InvalidElementStateError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "invalid element state";
   }
 }
 
+/** Argument was an invalid selector. */
 class InvalidSelectorError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "invalid selector";
   }
 }
 
+/**
+ * Occurs if the given session ID is not in the list of active sessions,
+ * meaning the session either does not exist or that it's not active.
+ */
 class InvalidSessionIDError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "invalid session id";
   }
 }
 
 /**
+ * An error occurred while executing JavaScript supplied by the user.
+ *
  * Creates a richly annotated error for an error situation that occurred
  * whilst evaluating injected scripts.
  */
 class JavaScriptError extends WebDriverError {
   /**
    * @param {(string|Error)} x
    *     An Error object instance or a string describing the error
    *     situation.
@@ -374,107 +398,148 @@ class JavaScriptError extends WebDriverE
     }
 
     super(msg);
     this.status = "javascript error";
     this.stack = trace;
   }
 }
 
+/**
+ * The target for mouse interaction is not in the browser's viewport
+ * and cannot be brought into that viewport.
+ */
 class MoveTargetOutOfBoundsError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "move target out of bounds";
   }
 }
 
+/**
+ * An attempt was made to operate on a modal dialog when one was
+ * not open.
+ */
 class NoAlertOpenError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "no such alert";
   }
 }
 
+/**
+ * An element could not be located on the page using the given
+ * search parameters.
+ */
 class NoSuchElementError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "no such element";
   }
 }
 
+/**
+ * A command to switch to a frame could not be satisfied because
+ * the frame could not be found.
+ */
 class NoSuchFrameError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "no such frame";
   }
 }
 
+/**
+ * A command to switch to a window could not be satisfied because
+ * the window could not be found.
+ */
 class NoSuchWindowError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "no such window";
   }
 }
 
+/** A script did not complete before its timeout expired. */
 class ScriptTimeoutError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "script timeout";
   }
 }
 
+/** A new session could not be created. */
 class SessionNotCreatedError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "session not created";
   }
 }
 
+/**
+ * A command failed because the referenced element is no longer
+ * attached to the DOM.
+ */
 class StaleElementReferenceError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "stale element reference";
   }
 }
 
+/** An operation did not complete before its timeout expired. */
 class TimeoutError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "timeout";
   }
 }
 
+/** A command to set a cookie's value could not be satisfied. */
 class UnableToSetCookieError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "unable to set cookie";
   }
 }
 
+/** A modal dialog was open, blocking this operation. */
 class UnexpectedAlertOpenError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "unexpected alert open";
   }
 }
 
+/**
+ * A command could not be executed because the remote end is not
+ * aware of it.
+ */
 class UnknownCommandError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "unknown command";
   }
 }
 
+/**
+ * An unknown error occurred in the remote end while processing
+ * the command.
+ */
 class UnknownError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "unknown error";
   }
 }
 
+/**
+ * Indicates that a command that should have executed properly
+ * cannot be supported for some reason.
+ */
 class UnsupportedOperationError extends WebDriverError {
   constructor(message) {
     super(message);
     this.status = "unsupported operation";
   }
 }
 
 const STATUSES = new Map([