X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/e1d6e76ab13e3bf753c747f80bbe09612f38b245..e307431f908eedae321aa86565fd5e213d758216:/m17app/src/error.rs diff --git a/m17app/src/error.rs b/m17app/src/error.rs index c1bcac1..6dbd8c2 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 from the M17 Rust Toolkit +#[derive(Debug, Error)] pub enum M17Error { #[error("given callsign contains at least one character invalid in M17: {0}")] InvalidCallsignCharacters(char), @@ -10,18 +11,7 @@ pub enum M17Error { #[error("given callsign is {0} characters long; maximum is 9")] CallsignTooLong(usize), - #[error("error during soundcard initialisation")] - SoundcardInit, - - #[error("unable to locate sound card '{0}' - is it in use?")] - SoundcardNotFound(String), - - #[error("unable to set up RTL-SDR receiver")] - RtlSdrInit, - - #[error( - "provided packet payload is too large: provided {provided} bytes, capacity {capacity}" - )] + #[error("provided packet payload is too large: provided {provided} bytes, capacity {capacity}")] PacketTooLarge { provided: usize, capacity: usize }, #[error("provided path to RRC file could not be opened: {0}")] @@ -29,4 +19,46 @@ 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), + + #[error("soundmodem component error: {0}")] + Soundmodem(#[source] SoundmodemError), } + +/// Arbitrary error type returned from adapters, which may be user-implemented +pub type AdapterError = Box; + +/// Arbitrary error type returned from soundmodem components, which may be user-implemented +pub type SoundmodemError = 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 { + let mut displays = vec![]; + for e in &self.0 { + displays.push(e.to_string()); + } + write!(f, "[{}]", displays.join(", ")) + } +} + +#[derive(Debug, Error)] +pub enum M17SoundmodemError {}