diff --git a/Cargo.lock b/Cargo.lock index 7db4f9fdb7f1..b611c62d3933 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6196,6 +6196,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", + "thiserror", "time 0.3.23", "tokio", "tokio-stream", diff --git a/testing/webdriver/Cargo.toml b/testing/webdriver/Cargo.toml index 494196428e15..4378444e0101 100644 --- a/testing/webdriver/Cargo.toml +++ b/testing/webdriver/Cargo.toml @@ -35,4 +35,5 @@ tokio = { version = "1.0", features = ["rt", "net"], optional = true} tokio-stream = { version = "0.1", features = ["net"], optional = true} unicode-segmentation = "1.2" url = "2.4" +thiserror = "1" warp = { version = "0.3", default-features = false, optional = true } diff --git a/testing/webdriver/src/error.rs b/testing/webdriver/src/error.rs index ed95fe227770..30464523878b 100644 --- a/testing/webdriver/src/error.rs +++ b/testing/webdriver/src/error.rs @@ -8,9 +8,9 @@ use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use std::borrow::Cow; use std::convert::From; -use std::error::Error; -use std::fmt; +use std::error; use std::io; +use thiserror::Error; #[derive(Debug, PartialEq)] pub enum ErrorStatus { @@ -292,8 +292,9 @@ impl From for ErrorStatus { pub type WebDriverResult = Result; -#[derive(Debug, PartialEq, Serialize)] +#[derive(Debug, PartialEq, Serialize, Error)] #[serde(remote = "Self")] +#[error("{}", .error.error_code())] pub struct WebDriverError { pub error: ErrorStatus, pub message: Cow<'static, str>, @@ -352,22 +353,6 @@ impl WebDriverError { } } -impl Error for WebDriverError { - fn description(&self) -> &str { - self.error_code() - } - - fn cause(&self) -> Option<&dyn Error> { - None - } -} - -impl fmt::Display for WebDriverError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.message.fmt(f) - } -} - impl From for WebDriverError { fn from(err: serde_json::Error) -> WebDriverError { WebDriverError::new(ErrorStatus::InvalidArgument, err.to_string()) @@ -386,8 +371,8 @@ impl From for WebDriverError { } } -impl From> for WebDriverError { - fn from(err: Box) -> WebDriverError { +impl From> for WebDriverError { + fn from(err: Box) -> WebDriverError { WebDriverError::new(ErrorStatus::UnknownError, err.to_string()) } }