Skip to content

Commit

Permalink
Merge pull request #4 from CleverCloud/devel/fdubois/feat/unrecoverab…
Browse files Browse the repository at this point in the history
…le-error

feat: implements a way to detect unrecoverable errors
  • Loading branch information
FlorentinDUBOIS authored Dec 8, 2023
2 parents 62e4ed2 + 080cf75 commit f194aa6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ pub mod unpooled;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("failed to create connection pool to Sōzu's socket")]
#[error("failed to create connection pool over unix socket, {0}")]
CreatePool(channel::Error),
#[error("failed to execute blocking task, {0}")]
Join(JoinError),
#[error("failed to get connection to socket, {0}")]
GetConnection(bb8::RunError<channel::Error>),
#[error("failed to send request to Sōzu, {0}")]
#[error("failed to send request, {0}")]
Send(ChannelError),
#[error("failed to read response from Sōzu, {0}")]
#[error("failed to read response, {0}")]
Receive(ChannelError),
#[error("got an invalid status code, {0}")]
InvalidStatusCode(i32),
#[error("failed to execute request on Sōzu")]
Failure(Response),
#[error("failed to execute request, got status '{0}', {1}")]
Failure(String, String, Response),
#[error("failed to create temporary directory, {0}")]
CreateTempDir(std::io::Error),
#[error("failed to create temporary file, {0}")]
Expand All @@ -63,6 +63,13 @@ impl From<JoinError> for Error {
}
}

impl Error {
#[tracing::instrument]
pub fn is_recoverable(&self) -> bool {
!matches!(self, Self::Send(_) | Self::Receive(_) | Self::CreatePool(_) | Self::GetConnection(_))
}
}

// -----------------------------------------------------------------------------
// Sender

Expand Down Expand Up @@ -108,7 +115,7 @@ impl Sender for Client {
match status {
ResponseStatus::Processing => continue,
ResponseStatus::Failure => {
return Err(Error::Failure(response));
return Err(Error::Failure(status.as_str_name().to_string(), response.message.to_string().to_lowercase(), response));
}
ResponseStatus::Ok => {
return Ok(response);
Expand Down

0 comments on commit f194aa6

Please sign in to comment.