From 10855536d76fbf48f0493a5d297ad2f043311b75 Mon Sep 17 00:00:00 2001 From: surajk-m Date: Wed, 18 Sep 2024 16:01:48 +0530 Subject: [PATCH] fix(session): Add `UnexpectedError(CmdError)` variant --- src/error.rs | 5 +++++ src/session.rs | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index da7356d..f5120bb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -24,6 +24,8 @@ pub enum NewSessionError { NotW3C(serde_json::Value), /// The WebDriver server refused to create a new session. SessionNotCreated(WebDriver), + /// An unexpected error occurred. + UnexpectedError(CmdError), } impl Error for NewSessionError { @@ -35,6 +37,7 @@ impl Error for NewSessionError { NewSessionError::Lost(..) => "webdriver server disconnected", NewSessionError::NotW3C(..) => "webdriver server gave non-conformant response", NewSessionError::SessionNotCreated(..) => "webdriver did not create session", + NewSessionError::UnexpectedError(..) => "unexpected webdriver error", } } @@ -46,6 +49,7 @@ impl Error for NewSessionError { NewSessionError::Lost(ref e) => Some(e), NewSessionError::NotW3C(..) => None, NewSessionError::SessionNotCreated(ref e) => Some(e), + NewSessionError::UnexpectedError(ref e) => Some(e), } } } @@ -61,6 +65,7 @@ impl fmt::Display for NewSessionError { NewSessionError::Lost(ref e) => write!(f, "{}", e), NewSessionError::NotW3C(ref e) => write!(f, "{:?}", e), NewSessionError::SessionNotCreated(ref e) => write!(f, "{}", e), + NewSessionError::UnexpectedError(ref e) => write!(f, "{}", e), } } } diff --git a/src/session.rs b/src/session.rs index 4af1b7e..726a0c2 100644 --- a/src/session.rs +++ b/src/session.rs @@ -601,9 +601,7 @@ where serde_json::to_value(e) .expect("error::WebDriver should always be serializeable to JSON"), )), - Err(e) => { - panic!("unexpected webdriver error; {}", e); - } + Err(e) => Err(error::NewSessionError::UnexpectedError(e)), } }