From dbe457d3fa2b2d83e57ffdd55a18046688494de0 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 21 Oct 2021 17:41:21 +0200 Subject: [PATCH] Improve clarity --- doc/book/src/cookbook/real_world.md | 4 ++-- src/api/error.rs | 8 ++++++-- src/rpc/rpc_helper.rs | 2 +- src/util/error.rs | 13 +++++-------- src/web/error.rs | 4 +++- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/doc/book/src/cookbook/real_world.md b/doc/book/src/cookbook/real_world.md index 5c773b5c..81921fc2 100644 --- a/doc/book/src/cookbook/real_world.md +++ b/doc/book/src/cookbook/real_world.md @@ -110,7 +110,7 @@ Mercury$ garage node-id 563e1ac825ee3323aa441e72c26d1030d6d4414aeb3dd25287c531e7fc2bc95d@[fc00:1::1]:3901 Venus$ garage node-id -86f0f26ae4afbd59aaf9cfb059eefac844951efd5b8caeec0d53f4ed6c85f332[fc00:1::2]:3901 +86f0f26ae4afbd59aaf9cfb059eefac844951efd5b8caeec0d53f4ed6c85f332@[fc00:1::2]:3901 etc. ``` @@ -120,7 +120,7 @@ You can then add these nodes to the `bootstrap_peers` list of at least one of yo ```toml bootstrap_peers = [ "563e1ac825ee3323aa441e72c26d1030d6d4414aeb3dd25287c531e7fc2bc95d@[fc00:1::1]:3901", - "86f0f26ae4afbd59aaf9cfb059eefac844951efd5b8caeec0d53f4ed6c85f332[fc00:1::2]:3901", + "86f0f26ae4afbd59aaf9cfb059eefac844951efd5b8caeec0d53f4ed6c85f332@[fc00:1::2]:3901", ... ] ``` 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::>(); - 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), + Quorum(usize, usize, usize, Vec), #[error(display = "Bad RPC: {}", _0)] BadRpc(String), @@ -110,11 +111,7 @@ where fn err_context>(self, ctx: C) -> Result { 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,