Skip to content

Commit

Permalink
fix(session): Add UnexpectedError(CmdError) variant
Browse files Browse the repository at this point in the history
  • Loading branch information
surajk-m authored and jonhoo committed Oct 19, 2024
1 parent 29bbfa7 commit 1085553
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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",
}
}

Expand All @@ -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),
}
}
}
Expand All @@ -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),
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}

Expand Down

0 comments on commit 1085553

Please sign in to comment.