Implement Display and Error for all errors
These standard traits should be implemented for all error types so they can match `dyn Error`, etc.dev/ci
parent
c8386f9dee
commit
ce2d77a32c
|
@ -26,6 +26,26 @@ impl From<Utf8Error> for MessageError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for MessageError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Io(e) => write!(f, "I/O error: {}", e),
|
||||||
|
Self::Parse(e) => write!(f, "Error parsing message: {}", e),
|
||||||
|
Self::Utf8(e) => write!(f, "Error parsing message: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for MessageError {
|
||||||
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
match self {
|
||||||
|
Self::Io(e) => Some(e),
|
||||||
|
Self::Parse(e) => Some(e),
|
||||||
|
Self::Utf8(e) => Some(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ConnectionError {
|
pub enum ConnectionError {
|
||||||
Message(MessageError),
|
Message(MessageError),
|
||||||
|
@ -50,3 +70,23 @@ impl From<serde_json::Error> for ConnectionError {
|
||||||
Self::Json(e)
|
Self::Json(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ConnectionError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Io(e) => write!(f, "I/O error: {}", e),
|
||||||
|
Self::Message(e) => write!(f, "Invalid message: {}", e),
|
||||||
|
Self::Json(e) => write!(f, "Could not parse JSON value: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for ConnectionError {
|
||||||
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
match self {
|
||||||
|
Self::Io(e) => Some(e),
|
||||||
|
Self::Message(e) => Some(e),
|
||||||
|
Self::Json(e) => Some(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,28 @@ impl From<ConnectionError> for SessionError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for SessionError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Browser(e) => write!(f, "Error launching browser: {}", e),
|
||||||
|
Self::Io(e) => write!(f, "I/O error: {}", e),
|
||||||
|
Self::Connection(e) => write!(f, "Connection error: {}", e),
|
||||||
|
Self::InvalidState(e) => write!(f, "Invalid state: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for SessionError {
|
||||||
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
match self {
|
||||||
|
Self::Browser(e) => Some(e),
|
||||||
|
Self::Io(e) => Some(e),
|
||||||
|
Self::Connection(e) => Some(e),
|
||||||
|
Self::InvalidState(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
browser: Browser,
|
browser: Browser,
|
||||||
marionette: Marionette,
|
marionette: Marionette,
|
||||||
|
|
Loading…
Reference in New Issue