From: Ian Jackson Date: Wed, 17 Feb 2021 22:27:38 +0000 (+0000) Subject: Provide AggregatedIE X-Git-Tag: otter-0.4.0~423 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=cd59beccc0785076a8c1a4d424116ca69e6493cc;p=otter.git Provide AggregatedIE Signed-off-by: Ian Jackson --- 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,