webdriver: error: include backtrace for errors originating from rust (#65)
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 30 Jan 2017 07:06:31 -0800
changeset 428110 907cce2619e6fb0f055873c01ef1afb8561a1e0b
parent 428109 6d7c8369a841962d5ef7dac85f8c7950f5f83bf0
child 428111 e05ac648612fa9a52568e0d0af52c245abde0fc6
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)
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
webdriver: error: include backtrace for errors originating from rust (#65) The WebDriver standard says the stacktrace field on error responses are implementation-defined, but the field cannot be omitted. The errors originating from Marionette are passed on without modification and include the expected stacktrace. This exposes a backtrace from the Rust crate with the same name for the errors originating from within the library itself. Fixes: https://github.com/mozilla/webdriver-rust/issues/63 Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 29ed83f0dfe4da5dbb2f143e867f145669812679 committer: jgraham <james@hoppipolla.co.uk>
testing/webdriver/Cargo.toml
testing/webdriver/src/error.rs
testing/webdriver/src/lib.rs
--- a/testing/webdriver/Cargo.toml
+++ b/testing/webdriver/Cargo.toml
@@ -3,14 +3,15 @@
 name = "webdriver"
 version = "0.19.0"
 authors = ["Mozilla Tools and Automation <auto-tools@mozilla.com>"]
 description = "Library implementing the wire protocol for the W3C WebDriver specification."
 repository = "https://github.com/jgraham/webdriver-rust"
 license = "MPL-2.0"
 
 [dependencies]
+backtrace = "0.3"
+cookie = {version = "0.2", default-features = false}
+hyper = {version = "0.9", default-features = false}
 log = "0.3"
 regex = "0.2"
 rustc-serialize = "0.3"
-hyper = {version = "0.9", default-features = false}
-cookie = {version = "0.2", default-features = false}
 time = "0.1"
--- a/testing/webdriver/src/error.rs
+++ b/testing/webdriver/src/error.rs
@@ -1,11 +1,12 @@
+use backtrace::Backtrace;
 use hyper::status::StatusCode;
 use rustc_serialize::base64::FromBase64Error;
-use rustc_serialize::json::{Json, ToJson, ParserError, DecoderError};
+use rustc_serialize::json::{DecoderError, Json, ParserError, ToJson};
 use std::borrow::Cow;
 use std::collections::BTreeMap;
 use std::convert::From;
 use std::error::Error;
 use std::fmt;
 use std::io::Error as IoError;
 
 #[derive(PartialEq, Debug)]
@@ -100,32 +101,34 @@ impl ErrorStatus {
 }
 
 pub type WebDriverResult<T> = Result<T, WebDriverError>;
 
 #[derive(Debug)]
 pub struct WebDriverError {
     pub error: ErrorStatus,
     pub message: Cow<'static, str>,
+    pub backtrace: Backtrace,
     pub delete_session: bool,
 }
 
 impl fmt::Display for WebDriverError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         self.message.fmt(f)
     }
 }
 
 impl WebDriverError {
     pub fn new<S>(error: ErrorStatus, message: S) -> WebDriverError
         where S: Into<Cow<'static, str>>
     {
         WebDriverError {
             error: error,
             message: message.into(),
+            backtrace: Backtrace::new(),
             delete_session: false,
         }
     }
 
     pub fn status_code(&self) -> &'static str {
         self.error.status_code()
     }
 
@@ -136,18 +139,20 @@ impl WebDriverError {
     pub fn to_json_string(&self) -> String {
         self.to_json().to_string()
     }
 }
 
 impl ToJson for WebDriverError {
     fn to_json(&self) -> Json {
         let mut data = BTreeMap::new();
-        data.insert("error".to_string(), self.status_code().to_json());
-        data.insert("message".to_string(), self.message.to_json());
+        data.insert("error".into(), self.status_code().to_json());
+        data.insert("message".into(), self.message.to_json());
+        data.insert("stacktrace".into(),
+                    format!("{:?}", self.backtrace).to_json());
         Json::Object(data)
     }
 }
 
 impl Error for WebDriverError {
     fn description(&self) -> &str {
         self.status_code()
     }
--- a/testing/webdriver/src/lib.rs
+++ b/testing/webdriver/src/lib.rs
@@ -1,27 +1,27 @@
 #![allow(non_snake_case)]
 
+extern crate backtrace;
 #[macro_use]
 extern crate log;
 extern crate rustc_serialize;
 extern crate hyper;
 extern crate regex;
 extern crate cookie;
 extern crate time;
 
 #[macro_use] pub mod macros;
 pub mod httpapi;
 pub mod command;
 pub mod common;
 pub mod error;
 pub mod server;
 pub mod response;
 
-
 #[cfg(test)]
 mod nullable_tests {
     use super::common::Nullable;
 
     #[test]
     fn test_nullable_map() {
         let mut test = Nullable::Value(21);