diff options
author | Alex Auvolat <alex@adnab.me> | 2021-10-21 17:41:21 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-10-21 17:43:42 +0200 |
commit | dbe457d3fa2b2d83e57ffdd55a18046688494de0 (patch) | |
tree | b97e07f1d3ef5e046d3334bd135740ad6b9c5268 /src | |
parent | bff5333c622ce5c8c3a151b4bd2d7ad2d04004c2 (diff) | |
download | garage-dbe457d3fa2b2d83e57ffdd55a18046688494de0.tar.gz garage-dbe457d3fa2b2d83e57ffdd55a18046688494de0.zip |
Improve clarity0.4-alpha
Diffstat (limited to 'src')
-rw-r--r-- | src/api/error.rs | 8 | ||||
-rw-r--r-- | src/rpc/rpc_helper.rs | 2 | ||||
-rw-r--r-- | src/util/error.rs | 13 | ||||
-rw-r--r-- | src/web/error.rs | 4 |
4 files changed, 15 insertions, 12 deletions
diff --git a/src/api/error.rs b/src/api/error.rs index 31ba7230..a57f926b 100644 --- a/src/api/error.rs +++ b/src/api/error.rs @@ -83,7 +83,9 @@ impl Error { Error::NotFound => StatusCode::NOT_FOUND, Error::Forbidden(_) => StatusCode::FORBIDDEN, Error::InternalError( - GarageError::Timeout | GarageError::RemoteError(_) | GarageError::Quorum(_, _, _), + GarageError::Timeout + | GarageError::RemoteError(_) + | GarageError::Quorum(_, _, _, _), ) => StatusCode::SERVICE_UNAVAILABLE, Error::InternalError(_) | Error::Hyper(_) | Error::Http(_) => { StatusCode::INTERNAL_SERVER_ERROR @@ -98,7 +100,9 @@ impl Error { Error::Forbidden(_) => "AccessDenied", Error::AuthorizationHeaderMalformed(_) => "AuthorizationHeaderMalformed", Error::InternalError( - GarageError::Timeout | GarageError::RemoteError(_) | GarageError::Quorum(_, _, _), + GarageError::Timeout + | GarageError::RemoteError(_) + | GarageError::Quorum(_, _, _, _), ) => "ServiceUnavailable", Error::InternalError(_) | Error::Hyper(_) | Error::Http(_) => "InternalError", _ => "InvalidRequest", diff --git a/src/rpc/rpc_helper.rs b/src/rpc/rpc_helper.rs index 7413508e..8c7cc681 100644 --- a/src/rpc/rpc_helper.rs +++ b/src/rpc/rpc_helper.rs @@ -203,7 +203,7 @@ impl RpcHelper { Ok(results) } else { let errors = errors.iter().map(|e| format!("{}", e)).collect::<Vec<_>>(); - Err(Error::Quorum(results.len(), to.len(), errors)) + Err(Error::Quorum(quorum, results.len(), to.len(), errors)) } } } diff --git a/src/util/error.rs b/src/util/error.rs index c8d3c680..626958da 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -48,12 +48,13 @@ pub enum Error { Timeout, #[error( - display = "Could not reach quorum. {} of {} request succeeded, others returned errors: {:?}", + display = "Could not reach quorum of {}. {} of {} request succeeded, others returned errors: {:?}", _0, _1, - _2 + _2, + _3 )] - Quorum(usize, usize, Vec<String>), + Quorum(usize, usize, usize, Vec<String>), #[error(display = "Bad RPC: {}", _0)] BadRpc(String), @@ -110,11 +111,7 @@ where fn err_context<C: std::borrow::Borrow<str>>(self, ctx: C) -> Result<T, Error> { match self { Ok(x) => Ok(x), - Err(e) => Err(Error::Message(format!( - "{}\nOriginal error: {}", - ctx.borrow(), - e - ))), + Err(e) => Err(Error::Message(format!("{}\n{}", ctx.borrow(), e))), } } } diff --git a/src/web/error.rs b/src/web/error.rs index 2ed7139f..426155c1 100644 --- a/src/web/error.rs +++ b/src/web/error.rs @@ -39,7 +39,9 @@ impl Error { Error::NotFound => StatusCode::NOT_FOUND, Error::ApiError(e) => e.http_status_code(), Error::InternalError( - GarageError::Timeout | GarageError::RemoteError(_) | GarageError::Quorum(_, _, _), + GarageError::Timeout + | GarageError::RemoteError(_) + | GarageError::Quorum(_, _, _, _), ) => StatusCode::SERVICE_UNAVAILABLE, Error::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR, _ => StatusCode::BAD_REQUEST, |