webdriver: error: enable custom stacktraces in WebDriverError
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 20 Apr 2017 13:55:59 +0100
changeset 428144 d313a2a5bc7e20173965cfb20113068b97502419
parent 428143 e1a198ffa22926895f81c40504707e70b0a14c4f
child 428145 a56d8bd25323d27ec5adcf35fd4987d96a54f5ba
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: enable custom stacktraces in WebDriverError With the new constructor WebDriverError::new_with_stack it is possible for consumers to set their own stacktraces. Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 46761f45b0e0fe70ec78acf360c492b800c8a60a committer: jgraham <james@hoppipolla.co.uk>
testing/webdriver/src/error.rs
--- a/testing/webdriver/src/error.rs
+++ b/testing/webdriver/src/error.rs
@@ -213,28 +213,39 @@ 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 stack: Cow<'static, str>,
     pub delete_session: bool,
 }
 
 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(),
+            stack: format!("{:?}", Backtrace::new()).into(),
+            delete_session: false,
+        }
+    }
+
+    pub fn new_with_stack<S>(error: ErrorStatus, message: S, stack: S) -> WebDriverError
+        where S: Into<Cow<'static, str>>
+    {
+        WebDriverError {
+            error: error,
+            message: message.into(),
+            stack: stack.into(),
             delete_session: false,
         }
     }
 
     pub fn error_code(&self) -> &'static str {
         self.error.error_code()
     }
 
@@ -247,18 +258,18 @@ impl WebDriverError {
     }
 }
 
 impl ToJson for WebDriverError {
     fn to_json(&self) -> Json {
         let mut data = BTreeMap::new();
         data.insert("error".into(), self.error_code().to_json());
         data.insert("message".into(), self.message.to_json());
-        data.insert("stacktrace".into(),
-                    format!("{:?}", self.backtrace).to_json());
+        data.insert("stacktrace".into(), self.stack.to_json());
+
         let mut wrapper = BTreeMap::new();
         wrapper.insert("value".into(), Json::Object(data));
         Json::Object(wrapper)
     }
 }
 
 impl Error for WebDriverError {
     fn description(&self) -> &str {