]> code.octet-stream.net Git - m17rt/blob - m17app/src/error.rs
aeb58a562a4f191313b250c3292d73920ac76d29
[m17rt] / m17app / src / error.rs
1 use std::{fmt::Display, path::PathBuf};
2
3 use thiserror::Error;
4
5 /// Errors originating from the M17 Rust Toolkit core
6 #[derive(Debug, Error)]
7 pub enum M17Error {
8 #[error("given callsign contains at least one character invalid in M17: {0}")]
9 InvalidCallsignCharacters(char),
10
11 #[error("given callsign is {0} characters long; maximum is 9")]
12 CallsignTooLong(usize),
13
14 #[error("error during soundcard initialisation")]
15 SoundcardInit,
16
17 #[error("unable to locate sound card '{0}' - is it in use?")]
18 SoundcardNotFound(String),
19
20 #[error("unable to set up RTL-SDR receiver")]
21 RtlSdrInit,
22
23 #[error(
24 "provided packet payload is too large: provided {provided} bytes, capacity {capacity}"
25 )]
26 PacketTooLarge { provided: usize, capacity: usize },
27
28 #[error("provided path to RRC file could not be opened: {0}")]
29 InvalidRrcPath(PathBuf),
30
31 #[error("failed to read from RRC file: {0}")]
32 RrcReadFailed(PathBuf),
33
34 #[error("tried to start app more than once")]
35 InvalidStart,
36
37 #[error("tried to close app that is not started")]
38 InvalidClose,
39
40 #[error("adapter error for id {0}: {1}")]
41 Adapter(usize, #[source] AdapterError),
42 }
43
44 pub type AdapterError = Box<dyn std::error::Error + Sync + Send + 'static>;
45
46 /// Iterator over potentially multiple errors
47 #[derive(Debug, Error)]
48 pub struct M17Errors(pub(crate) Vec<M17Error>);
49 impl Iterator for M17Errors {
50 type Item = M17Error;
51
52 fn next(&mut self) -> Option<Self::Item> {
53 self.0.pop()
54 }
55 }
56
57 impl Display for M17Errors {
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 write!(f, "{:?}", self.0)
60 }
61 }