1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug, Error)]
7pub enum Error {
8 #[error(transparent)]
9 Io(#[from] std::io::Error),
10
11 #[error(transparent)]
12 Serial(#[from] serialport::Error),
13
14 #[error("probe-rs error: {0}")]
15 ProbeRs(#[from] probe_rs::Error),
16
17 #[error("Intel HEX parse error: {0}")]
18 IntelHex(#[from] ihex::ReaderError),
19
20 #[error("ELF parse error: {0}")]
21 Elf(#[from] goblin::error::Error),
22
23 #[error("integer parse error: {0}")]
24 ParseInt(#[from] std::num::ParseIntError),
25
26 #[error("protocol error: {0}")]
27 Protocol(String),
28
29 #[error("invalid input: {0}")]
30 InvalidInput(String),
31
32 #[error("timeout while {0}")]
33 Timeout(String),
34
35 #[error("configuration error: {0}")]
36 Config(String),
37
38 #[error("unsupported chip: {0}")]
39 UnsupportedChip(String),
40
41 #[error("unsupported memory: {0}")]
42 UnsupportedMemory(String),
43
44 #[error("CRC mismatch: expected {expected:#010X}, got {actual:#010X}")]
45 CrcMismatch { expected: u32, actual: u32 },
46
47 #[error("embedded asset `{0}` not found")]
48 MissingEmbeddedAsset(&'static str),
49}
50
51impl Error {
52 pub fn protocol(msg: impl Into<String>) -> Self {
53 Self::Protocol(msg.into())
54 }
55
56 pub fn invalid_input(msg: impl Into<String>) -> Self {
57 Self::InvalidInput(msg.into())
58 }
59
60 pub fn timeout(msg: impl Into<String>) -> Self {
61 Self::Timeout(msg.into())
62 }
63}