Bug 1411026 - Rename MarionetteError::status to ::code. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 23 Oct 2017 21:53:06 +0100
changeset 684970 d456df13a28b1c9bf5ae5d12977ba3567ef676d8
parent 684969 aef26c88de47f18f04011b1f1de9ff4381969141
child 684971 bf6fa7034b18eec63abaf7fa3b476545ea06f7af
push id85783
push userbmo:ato@sny.no
push dateMon, 23 Oct 2017 21:00:48 +0000
reviewerswhimboo
bugs1411026
milestone58.0a1
Bug 1411026 - Rename MarionetteError::status to ::code. r?whimboo For errors originating from Marionette we talk about "error codes", not about "error statuses". This patch fixes the JSON serialisation method Marionette::to_json which incorrectly serialised the error code as "status"; it should be "error". This also removes the MarionetteError::new constructor as we have no need to allow explicit construction of MarionetteError's. MozReview-Commit-ID: 7gjz0ebkMIU
testing/geckodriver/src/marionette.rs
--- a/testing/geckodriver/src/marionette.rs
+++ b/testing/geckodriver/src/marionette.rs
@@ -1249,63 +1249,55 @@ impl ToJson for MarionetteResponse {
     fn to_json(&self) -> Json {
         Json::Array(vec![Json::U64(1), self.id.to_json(), self.error.to_json(),
                          self.result.clone()])
     }
 }
 
 #[derive(RustcEncodable, RustcDecodable)]
 pub struct MarionetteError {
-    pub status: String,
+    pub code: String,
     pub message: String,
     pub stacktrace: Option<String>
 }
 
 impl MarionetteError {
-    fn new(status: String, message: String, stacktrace: Option<String>) -> MarionetteError {
-        MarionetteError {
-            status: status,
-            message: message,
-            stacktrace: stacktrace
-        }
-    }
-
     fn from_json(data: &Json) -> WebDriverResult<MarionetteError> {
         if !data.is_object() {
             return Err(WebDriverError::new(ErrorStatus::UnknownError,
                                            "Expected an error object"));
         }
-        let status = try_opt!(
+
+        let code = try_opt!(
             try_opt!(data.find("error"),
                      ErrorStatus::UnknownError,
-                     "Error value has no status").as_string(),
+                     "Error value has no error code").as_string(),
             ErrorStatus::UnknownError,
             "Error status was not a string").into();
-
         let message = try_opt!(
             try_opt!(data.find("message"),
                      ErrorStatus::UnknownError,
                      "Error value has no message").as_string(),
             ErrorStatus::UnknownError,
             "Error message was not a string").into();
-
         let stacktrace = match data.find("stacktrace") {
             None | Some(&Json::Null) => None,
             Some(x) => Some(try_opt!(x.as_string(),
                                      ErrorStatus::UnknownError,
                                      "Error message was not a string").into()),
         };
-        Ok(MarionetteError::new(status, message, stacktrace))
+
+        Ok(MarionetteError { code, message, stacktrace })
     }
 }
 
 impl ToJson for MarionetteError {
     fn to_json(&self) -> Json {
         let mut data = BTreeMap::new();
-        data.insert("status".into(), self.status.to_json());
+        data.insert("error".into(), self.code.to_json());
         data.insert("message".into(), self.message.to_json());
         data.insert("stacktrace".into(), self.stacktrace.to_json());
         Json::Object(data)
     }
 }
 
 fn get_free_port() -> IoResult<u16> {
     TcpListener::bind(&("localhost", 0))