From 01a8acdeecfcacafb61809f9e135709148e842ce Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 23 Apr 2020 16:23:06 +0000 Subject: [PATCH] Better error reporting --- src/error.rs | 1 + src/main.rs | 2 +- src/rpc_client.rs | 9 ++++----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/error.rs b/src/error.rs index d0a46f39..e217f9ae 100644 --- a/src/error.rs +++ b/src/error.rs @@ -67,6 +67,7 @@ impl Error { match self { Error::BadRequest(_) => StatusCode::BAD_REQUEST, Error::NotFound => StatusCode::NOT_FOUND, + Error::RPC(_) => StatusCode::SERVICE_UNAVAILABLE, _ => StatusCode::INTERNAL_SERVER_ERROR, } } diff --git a/src/main.rs b/src/main.rs index 06f0fe98..0b41805b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -326,7 +326,7 @@ async fn cmd_status(rpc_cli: RpcAddrClient, rpc_host: SocketAddr) -> Re cfg.tag, cfg.datacenter, cfg.n_tokens, - (now_msec() - adv.last_seen)/1000, + (now_msec() - adv.last_seen) / 1000, ); } } diff --git a/src/rpc_client.rs b/src/rpc_client.rs index c083fcfd..ba036c60 100644 --- a/src/rpc_client.rs +++ b/src/rpc_client.rs @@ -41,6 +41,8 @@ pub enum RPCError { RMPEncode(#[error(source)] rmp_serde::encode::Error), #[error(display = "Messagepack decode error: {}", _0)] RMPDecode(#[error(source)] rmp_serde::decode::Error), + #[error(display = "Too many errors: {:?}", _0)] + TooManyErrors(Vec), } #[derive(Copy, Clone)] @@ -222,11 +224,8 @@ impl RpcClient { Ok(results) } else { - let mut msg = "Too many failures:".to_string(); - for e in errors { - msg += &format!("\n{}", e); - } - Err(Error::Message(msg)) + let errors = errors.iter().map(|e| format!("{}", e)).collect::>(); + Err(Error::from(RPCError::TooManyErrors(errors))) } } }