Skip to content

Commit

Permalink
Merge pull request #274 from scylladb/fix_error_propagation
Browse files Browse the repository at this point in the history
Make error message propagation more robust
  • Loading branch information
piodul authored Jul 23, 2021
2 parents 4430bd1 + b87916c commit 585718a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions scylla/src/frame/frame_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use thiserror::Error;

#[derive(Error, Debug)]
pub enum FrameError {
#[error("Type parsing failed")]
#[error(transparent)]
Parse(#[from] ParseError),
#[error("Frame is compressed, but no compression negotiated for connection.")]
NoCompressionNegotiated,
Expand All @@ -29,7 +29,7 @@ pub enum FrameError {

#[derive(Error, Debug)]
pub enum ParseError {
#[error("Bad data - couldn't serialize. Error msg: {0}")]
#[error("Could not serialize frame: {0}")]
BadData(String),
#[error(transparent)]
IoError(#[from] std::io::Error),
Expand Down
2 changes: 1 addition & 1 deletion scylla/src/frame/request/auth_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Request for AuthResponse {
fn serialize(&self, buf: &mut impl BufMut) -> Result<(), ParseError> {
if self.username.is_none() || self.password.is_none() {
return Err(ParseError::BadData(
"Bad credentials given - username and password shouldn't be none".to_string(),
"Bad credentials: username or password missing. You can use SessionBuilder::user(\"user\", \"pass\") to provide credentials.".to_string(),
));
}
let username_as_bytes = self.username.as_ref().unwrap().as_bytes();
Expand Down
21 changes: 15 additions & 6 deletions scylla/src/transport/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ pub enum QueryError {
#[error("IO Error: {0}")]
IoError(Arc<std::io::Error>),

/// Unexpected or invalid message received
/// Unexpected message received
#[error("Protocol Error: {0}")]
ProtocolError(&'static str),

/// Invalid message received
#[error("Invalid message: {0}")]
InvalidMessage(String),

/// Timeout error has occured, function didn't complete in time.
#[error("Timeout Error")]
TimeoutError,
Expand Down Expand Up @@ -261,10 +265,14 @@ pub enum NewSessionError {
#[error("IO Error: {0}")]
IoError(Arc<std::io::Error>),

/// Unexpected or invalid message received
/// Unexpected message received
#[error("Protocol Error: {0}")]
ProtocolError(&'static str),

/// Invalid message received
#[error("Invalid message: {0}")]
InvalidMessage(String),

/// Timeout error has occured, couldn't connect to node in time.
#[error("Timeout Error")]
TimeoutError,
Expand Down Expand Up @@ -305,14 +313,14 @@ impl From<SerializeValuesError> for QueryError {
}

impl From<ParseError> for QueryError {
fn from(_parse_error: ParseError) -> QueryError {
QueryError::ProtocolError("Error parsing message")
fn from(parse_error: ParseError) -> QueryError {
QueryError::InvalidMessage(format!("Error parsing message: {}", parse_error))
}
}

impl From<FrameError> for QueryError {
fn from(_frame_error: FrameError) -> QueryError {
QueryError::ProtocolError("Error parsing message frame")
fn from(frame_error: FrameError) -> QueryError {
QueryError::InvalidMessage(format!("Frame error: {}", frame_error))
}
}

Expand All @@ -329,6 +337,7 @@ impl From<QueryError> for NewSessionError {
QueryError::BadQuery(e) => NewSessionError::BadQuery(e),
QueryError::IoError(e) => NewSessionError::IoError(e),
QueryError::ProtocolError(m) => NewSessionError::ProtocolError(m),
QueryError::InvalidMessage(m) => NewSessionError::InvalidMessage(m),
QueryError::TimeoutError => NewSessionError::TimeoutError,
}
}
Expand Down

0 comments on commit 585718a

Please sign in to comment.