|
5 | 5 | use std::io; |
6 | 6 | use thiserror::Error; |
7 | 7 |
|
8 | | -// TODO(george-cosma): Split this. Possibly each meta-function (install, list, |
9 | | -// ...) should have its own error type + error type for connection. We can have |
10 | | -// more detailed errors as "sources" for more generic error types, if we TRULY |
11 | | -// need to know why probe-rs failed. Or serial. |
12 | | - |
13 | 8 | #[derive(Debug, Error)] |
14 | 9 | pub enum TockloaderError { |
15 | | - #[error("Failed due to the connection not being open.")] |
16 | | - ConnectionNotOpen, |
17 | | - |
18 | | - #[error("Error occurred while trying to access core: {0}")] |
19 | | - CoreAccessError(usize, probe_rs::Error), |
20 | | - |
21 | | - #[error("Failed to initialize probe_rs connection due to a communication error. Inner: {0}")] |
22 | | - ProbeRsInitializationError(#[from] probe_rs::probe::DebugProbeError), |
| 10 | + #[error("Serial connection error: {0}")] |
| 11 | + Serial(#[from] SerialError), |
23 | 12 |
|
24 | | - #[error("Failed to establish communication with board. Inner: {0}")] |
25 | | - ProbeRsCommunicationError(probe_rs::Error), |
| 13 | + #[error("Probe connection error: {0}")] |
| 14 | + Probe(#[from] ProbeError), |
26 | 15 |
|
27 | | - #[error("Failed to read from debug probe. Inner: {0}")] |
28 | | - ProbeRsReadError(probe_rs::Error), |
| 16 | + #[error("TAB file error: {0}")] |
| 17 | + Tab(#[from] TabError), |
29 | 18 |
|
30 | | - #[error("Failed to write binary. Inner: {0}")] |
31 | | - ProbeRsWriteError(#[from] probe_rs::flashing::FlashError), |
| 19 | + #[error("Tock OS error: {0}")] |
| 20 | + Tock(#[from] TockError), |
32 | 21 |
|
33 | | - #[error("Failed to initialize serial connection due to a communication error. Inner: {0}")] |
34 | | - SerialInitializationError(#[from] tokio_serial::Error), |
| 22 | + #[error("Internal tockloader error: {0}")] |
| 23 | + Internal(#[from] InternalError), |
| 24 | +} |
35 | 25 |
|
36 | | - #[error("Bootloader did not respond properly: {0}")] |
37 | | - BootloaderError(u8), |
| 26 | +#[derive(Debug, Error)] |
| 27 | +pub enum SerialError { |
| 28 | + #[error("Failed to interface in serial using tokio_serial: {0}")] |
| 29 | + TokioSerial(#[from] tokio_serial::Error), |
38 | 30 |
|
39 | | - #[error("No binary found for {0} architecture.")] |
40 | | - NoBinaryError(String), |
| 31 | + #[error("Failed to perform read/write operations on serial port: {0}")] |
| 32 | + IO(#[from] io::Error), |
| 33 | +} |
41 | 34 |
|
42 | | - #[error("App data could not be parsed.")] |
43 | | - ParsingError(tbf_parser::types::TbfParseError), |
| 35 | +#[derive(Debug, Error)] |
| 36 | +pub enum ProbeError { |
| 37 | + #[error("Failed to interact with probe: {0}")] |
| 38 | + Probe(#[from] probe_rs::probe::DebugProbeError), |
44 | 39 |
|
45 | | - #[error("Failed to perform read/write operations on serial port. Inner: {0}")] |
46 | | - IOError(#[from] io::Error), |
| 40 | + #[error("Communication with board failed: {0}")] |
| 41 | + Communication(#[from] probe_rs::Error), |
47 | 42 |
|
48 | | - #[error("Expected board attribute to be present")] |
49 | | - MisconfiguredBoard(String), |
| 43 | + #[error("Failed to flash data: {0}")] |
| 44 | + Flashing(#[from] probe_rs::flashing::FlashError), |
| 45 | +} |
50 | 46 |
|
51 | | - #[error("Failed to use tab from provided path. Inner: {0}")] |
52 | | - UnusableTab(io::Error), |
| 47 | +#[derive(Debug, Error)] |
| 48 | +pub enum TabError { |
| 49 | + #[error("Failed to use tab from provided path: {0}")] |
| 50 | + Unusable(io::Error), |
53 | 51 |
|
54 | | - #[error("Failed to parse metadata. Inner: {0}")] |
| 52 | + #[error("Failed to parse metadata: {0}")] |
55 | 53 | InvalidMetadata(toml::de::Error), |
56 | 54 |
|
57 | | - #[error("No metadata.toml found.")] |
| 55 | + #[error("No metadata.toml found")] |
58 | 56 | NoMetadata, |
| 57 | + |
| 58 | + #[error("App data could not be parsed: {0:?}")] |
| 59 | + Parsing(tbf_parser::types::TbfParseError), |
| 60 | + |
| 61 | + #[error("No binary found for {0} architecture")] |
| 62 | + NoBinary(String), |
| 63 | +} |
| 64 | + |
| 65 | +#[derive(Debug, Error)] |
| 66 | +pub enum TockError { |
| 67 | + #[error("Bootloader did not respond properly: {0}")] |
| 68 | + Bootloader(u8), |
| 69 | + |
| 70 | + #[error("Expected board attribute to be present: {0}")] |
| 71 | + MisconfiguredBoard(String), |
| 72 | +} |
| 73 | + |
| 74 | +#[derive(Debug, Error)] |
| 75 | +pub enum InternalError { |
| 76 | + #[error("Operation failed due to board not being open.")] |
| 77 | + ConnectionNotOpen, |
| 78 | + |
| 79 | + #[error("Operation failed due to board not being in bootloader mode or not having a bootloader present.")] |
| 80 | + BootloaderNotPresent, |
59 | 81 | } |
0 commit comments