errors: distinguish invalid frames from unexpected ones
Invalid frames (e.g. ones which are not parsable) are now distinguished
from frames which are syntactically valid, but arrive at unexpected
times.
@@ -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,
@@ -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,
@@ -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!("Error parsing message frame: {}", frame_error))
}
}
@@ -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,
}
}
