X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/e1d6e76ab13e3bf753c747f80bbe09612f38b245..54fc21708c9121409560731f90b91e59699f4ddc:/m17app/src/error.rs?ds=sidebyside diff --git a/m17app/src/error.rs b/m17app/src/error.rs index c1bcac1..aeb58a5 100644 --- a/m17app/src/error.rs +++ b/m17app/src/error.rs @@ -1,8 +1,9 @@ -use std::path::PathBuf; +use std::{fmt::Display, path::PathBuf}; use thiserror::Error; -#[derive(Debug, Error, PartialEq, Eq, Clone)] +/// Errors originating from the M17 Rust Toolkit core +#[derive(Debug, Error)] pub enum M17Error { #[error("given callsign contains at least one character invalid in M17: {0}")] InvalidCallsignCharacters(char), @@ -29,4 +30,32 @@ pub enum M17Error { #[error("failed to read from RRC file: {0}")] RrcReadFailed(PathBuf), + + #[error("tried to start app more than once")] + InvalidStart, + + #[error("tried to close app that is not started")] + InvalidClose, + + #[error("adapter error for id {0}: {1}")] + Adapter(usize, #[source] AdapterError), +} + +pub type AdapterError = Box; + +/// Iterator over potentially multiple errors +#[derive(Debug, Error)] +pub struct M17Errors(pub(crate) Vec); +impl Iterator for M17Errors { + type Item = M17Error; + + fn next(&mut self) -> Option { + self.0.pop() + } +} + +impl Display for M17Errors { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } }