From cd59beccc0785076a8c1a4d424116ca69e6493cc Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 17 Feb 2021 22:27:38 +0000 Subject: [PATCH] Provide AggregatedIE Signed-off-by: Ian Jackson --- src/error.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/error.rs b/src/error.rs index 3244cde1..68a2b588 100644 --- a/src/error.rs +++ b/src/error.rs @@ -53,6 +53,8 @@ pub enum InternalError { Anyhow(#[from] anyhow::Error), #[error("Game contains only partial data for player, or account missing")] PartialPlayerData, + #[error("Multiple errors occurred where only one could be reported")] + Aggregated, } #[derive(Error)] @@ -154,6 +156,30 @@ pub type StartupError = anyhow::Error; pub use OnlineError::{NoClient,NoPlayer}; +pub enum AggregatedIE { + Ok, + One(InternalError), + Many, +} + +impl AggregatedIE { + pub fn new() -> Self { Self::Ok } + pub fn record(&mut self, e: InternalError) { + error!("error occurred in aggregating-errors contest: {}", &e); + *self = match self { + Self::Ok => Self::One(e), + _ => Self::Many, + } + } + pub fn ok(self) -> Result<(),IE> { + match self { + Self::Ok => Ok(()), + Self::One(e) => Err(e), + Self::Many => Err(IE::Aggregated), + } + } +} + #[derive(Error,Debug)] pub enum InstanceLockError { GameCorrupted, -- 2.30.2