mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1866273: Use thiserror crate for webdriver r=webdriver-reviewers,jgraham
Differential Revision: https://phabricator.services.mozilla.com/D194693
This commit is contained in:
parent
5fa3513e8e
commit
1a7feedf6f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6196,6 +6196,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"time 0.3.23",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
|
@ -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 }
|
||||
|
@ -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<String> for ErrorStatus {
|
||||
|
||||
pub type WebDriverResult<T> = Result<T, WebDriverError>;
|
||||
|
||||
#[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<serde_json::Error> for WebDriverError {
|
||||
fn from(err: serde_json::Error) -> WebDriverError {
|
||||
WebDriverError::new(ErrorStatus::InvalidArgument, err.to_string())
|
||||
@ -386,8 +371,8 @@ impl From<DecodeError> for WebDriverError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn Error>> for WebDriverError {
|
||||
fn from(err: Box<dyn Error>) -> WebDriverError {
|
||||
impl From<Box<dyn error::Error>> for WebDriverError {
|
||||
fn from(err: Box<dyn error::Error>) -> WebDriverError {
|
||||
WebDriverError::new(ErrorStatus::UnknownError, err.to_string())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user