From bff5333c622ce5c8c3a151b4bd2d7ad2d04004c2 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 21 Oct 2021 17:29:27 +0200 Subject: Move things around, improvements to CLI --- src/util/error.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/util/error.rs') diff --git a/src/util/error.rs b/src/util/error.rs index 390327f1..c8d3c680 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -47,8 +47,13 @@ pub enum Error { #[error(display = "Timeout")] Timeout, - #[error(display = "Too many errors: {:?}", _0)] - TooManyErrors(Vec), + #[error( + display = "Could not reach quorum. {} of {} request succeeded, others returned errors: {:?}", + _0, + _1, + _2 + )] + Quorum(usize, usize, Vec), #[error(display = "Bad RPC: {}", _0)] BadRpc(String), @@ -81,6 +86,39 @@ impl From> for Error { } } +impl<'a> From<&'a str> for Error { + fn from(v: &'a str) -> Error { + Error::Message(v.to_string()) + } +} + +impl From for Error { + fn from(v: String) -> Error { + Error::Message(v) + } +} + +pub trait ErrorContext { + fn err_context>(self, ctx: C) -> Result; +} + +impl ErrorContext for Result +where + E: std::fmt::Display, +{ + #[inline] + fn err_context>(self, ctx: C) -> Result { + match self { + Ok(x) => Ok(x), + Err(e) => Err(Error::Message(format!( + "{}\nOriginal error: {}", + ctx.borrow(), + e + ))), + } + } +} + // Custom serialization for our error type, for use in RPC. // Errors are serialized as a string of their Display representation. // Upon deserialization, they all become a RemoteError with the -- cgit v1.2.3