Bug 1396831 - Improve readability of error_code and http_status. r=jgraham
authorAndreas Tolfsen <ato@sny.no>
Tue, 05 Sep 2017 14:39:32 +0100
changeset 428419 b763a58280a37f70028284d2755036dd3ce806ac
parent 428418 f77d12a3fc036175347a04b1ae3719a640706ca3
child 428420 bcd74edc5749d59828144f1414411022f1e4f5b5
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgraham
bugs1396831
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1396831 - Improve readability of error_code and http_status. r=jgraham No semantic changes. MozReview-Commit-ID: F4TJI2i5bJo
testing/webdriver/src/error.rs
--- a/testing/webdriver/src/error.rs
+++ b/testing/webdriver/src/error.rs
@@ -139,80 +139,83 @@ pub enum ErrorStatus {
     /// Indicates that a [command] that should have executed properly is not
     /// currently supported.
     UnsupportedOperation,
 }
 
 
 impl ErrorStatus {
     pub fn error_code(&self) -> &'static str {
+        use self::ErrorStatus::*;
         match *self {
-            ErrorStatus::ElementClickIntercepted => "element click intercepted",
-            ErrorStatus::ElementNotInteractable => "element not interactable",
-            ErrorStatus::ElementNotSelectable => "element not selectable",
-            ErrorStatus::InsecureCertificate => "insecure certificate",
-            ErrorStatus::InvalidArgument => "invalid argument",
-            ErrorStatus::InvalidCookieDomain => "invalid cookie domain",
-            ErrorStatus::InvalidCoordinates => "invalid coordinates",
-            ErrorStatus::InvalidElementState => "invalid element state",
-            ErrorStatus::InvalidSelector => "invalid selector",
-            ErrorStatus::InvalidSessionId => "invalid session id",
-            ErrorStatus::JavascriptError => "javascript error",
-            ErrorStatus::MoveTargetOutOfBounds => "move target out of bounds",
-            ErrorStatus::NoSuchAlert => "no such alert",
-            ErrorStatus::NoSuchCookie => "no such cookie",
-            ErrorStatus::NoSuchElement => "no such element",
-            ErrorStatus::NoSuchFrame => "no such frame",
-            ErrorStatus::NoSuchWindow => "no such window",
-            ErrorStatus::ScriptTimeout => "script timeout",
-            ErrorStatus::SessionNotCreated => "session not created",
-            ErrorStatus::StaleElementReference => "stale element reference",
-            ErrorStatus::Timeout => "timeout",
-            ErrorStatus::UnableToCaptureScreen => "unable to capture screen",
-            ErrorStatus::UnableToSetCookie => "unable to set cookie",
-            ErrorStatus::UnexpectedAlertOpen => "unexpected alert open",
-            ErrorStatus::UnknownCommand |
-            ErrorStatus::UnknownError => "unknown error",
-            ErrorStatus::UnknownMethod => "unknown method",
-            ErrorStatus::UnknownPath => "unknown command",
-            ErrorStatus::UnsupportedOperation => "unsupported operation",
+            ElementClickIntercepted => "element click intercepted",
+            ElementNotInteractable => "element not interactable",
+            ElementNotSelectable => "element not selectable",
+            InsecureCertificate => "insecure certificate",
+            InvalidArgument => "invalid argument",
+            InvalidCookieDomain => "invalid cookie domain",
+            InvalidCoordinates => "invalid coordinates",
+            InvalidElementState => "invalid element state",
+            InvalidSelector => "invalid selector",
+            InvalidSessionId => "invalid session id",
+            JavascriptError => "javascript error",
+            MoveTargetOutOfBounds => "move target out of bounds",
+            NoSuchAlert => "no such alert",
+            NoSuchCookie => "no such cookie",
+            NoSuchElement => "no such element",
+            NoSuchFrame => "no such frame",
+            NoSuchWindow => "no such window",
+            ScriptTimeout => "script timeout",
+            SessionNotCreated => "session not created",
+            StaleElementReference => "stale element reference",
+            Timeout => "timeout",
+            UnableToCaptureScreen => "unable to capture screen",
+            UnableToSetCookie => "unable to set cookie",
+            UnexpectedAlertOpen => "unexpected alert open",
+            UnknownCommand |
+            UnknownError => "unknown error",
+            UnknownMethod => "unknown method",
+            UnknownPath => "unknown command",
+            UnsupportedOperation => "unsupported operation",
         }
     }
 
     pub fn http_status(&self) -> StatusCode {
+        use self::ErrorStatus::*;
+        use self::StatusCode::*;
         match *self {
-            ErrorStatus::ElementClickIntercepted => StatusCode::BadRequest,
-            ErrorStatus::ElementNotInteractable => StatusCode::BadRequest,
-            ErrorStatus::ElementNotSelectable => StatusCode::BadRequest,
-            ErrorStatus::InsecureCertificate => StatusCode::BadRequest,
-            ErrorStatus::InvalidArgument => StatusCode::BadRequest,
-            ErrorStatus::InvalidCookieDomain => StatusCode::BadRequest,
-            ErrorStatus::InvalidCoordinates => StatusCode::BadRequest,
-            ErrorStatus::InvalidElementState => StatusCode::BadRequest,
-            ErrorStatus::InvalidSelector => StatusCode::BadRequest,
-            ErrorStatus::InvalidSessionId => StatusCode::NotFound,
-            ErrorStatus::JavascriptError => StatusCode::InternalServerError,
-            ErrorStatus::MoveTargetOutOfBounds => StatusCode::InternalServerError,
-            ErrorStatus::NoSuchAlert => StatusCode::BadRequest,
-            ErrorStatus::NoSuchCookie => StatusCode::NotFound,
-            ErrorStatus::NoSuchElement => StatusCode::NotFound,
-            ErrorStatus::NoSuchFrame => StatusCode::BadRequest,
-            ErrorStatus::NoSuchWindow => StatusCode::BadRequest,
-            ErrorStatus::ScriptTimeout => StatusCode::RequestTimeout,
-            ErrorStatus::SessionNotCreated => StatusCode::InternalServerError,
-            ErrorStatus::StaleElementReference => StatusCode::BadRequest,
-            ErrorStatus::Timeout => StatusCode::RequestTimeout,
-            ErrorStatus::UnableToCaptureScreen => StatusCode::BadRequest,
-            ErrorStatus::UnableToSetCookie => StatusCode::InternalServerError,
-            ErrorStatus::UnexpectedAlertOpen => StatusCode::InternalServerError,
-            ErrorStatus::UnknownCommand => StatusCode::NotFound,
-            ErrorStatus::UnknownError => StatusCode::InternalServerError,
-            ErrorStatus::UnknownMethod => StatusCode::MethodNotAllowed,
-            ErrorStatus::UnknownPath => StatusCode::NotFound,
-            ErrorStatus::UnsupportedOperation => StatusCode::InternalServerError,
+            ElementClickIntercepted => BadRequest,
+            ElementNotInteractable => BadRequest,
+            ElementNotSelectable => BadRequest,
+            InsecureCertificate => BadRequest,
+            InvalidArgument => BadRequest,
+            InvalidCookieDomain => BadRequest,
+            InvalidCoordinates => BadRequest,
+            InvalidElementState => BadRequest,
+            InvalidSelector => BadRequest,
+            InvalidSessionId => NotFound,
+            JavascriptError => InternalServerError,
+            MoveTargetOutOfBounds => InternalServerError,
+            NoSuchAlert => BadRequest,
+            NoSuchCookie => NotFound,
+            NoSuchElement => NotFound,
+            NoSuchFrame => BadRequest,
+            NoSuchWindow => BadRequest,
+            ScriptTimeout => RequestTimeout,
+            SessionNotCreated => InternalServerError,
+            StaleElementReference => BadRequest,
+            Timeout => RequestTimeout,
+            UnableToCaptureScreen => BadRequest,
+            UnableToSetCookie => InternalServerError,
+            UnexpectedAlertOpen => InternalServerError,
+            UnknownCommand => NotFound,
+            UnknownError => InternalServerError,
+            UnknownMethod => MethodNotAllowed,
+            UnknownPath => NotFound,
+            UnsupportedOperation => InternalServerError,
         }
     }
 }
 
 pub type WebDriverResult<T> = Result<T, WebDriverError>;
 
 #[derive(Debug)]
 pub struct WebDriverError {