1use thiserror::Error;
6
7pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Error, Debug)]
12pub enum Error {
13 #[error("USB error: {0}")]
15 Usb(#[from] nusb::Error),
16
17 #[error("Programmer not found. Is the CH341A connected?")]
19 ProgrammerNotFound,
20
21 #[error("Flash chip not detected. Check connections and power.")]
23 FlashNotDetected,
24
25 #[error("Unsupported flash chip: JEDEC ID = {0:02X} {1:02X} {2:02X}")]
27 UnsupportedChip(u8, u8, u8),
28
29 #[error(
31 "Verification failed at address 0x{address:08X}: expected {expected:02X}, got {actual:02X}"
32 )]
33 VerificationFailed {
34 address: u32,
35 expected: u8,
36 actual: u8,
37 },
38
39 #[error("Erase failed at block {block}")]
41 EraseFailed { block: u32 },
42
43 #[error("Write failed at address 0x{address:08X}")]
45 WriteFailed { address: u32 },
46
47 #[error("Read failed at address 0x{address:08X}")]
49 ReadFailed { address: u32 },
50
51 #[error("Uncorrectable ECC error at address 0x{address:08X}")]
53 EccError { address: u32 },
54
55 #[error("Bad block detected at block {block}")]
57 BadBlock { block: u32 },
58
59 #[error("Operation timed out")]
61 Timeout,
62
63 #[error("Invalid parameter: {0}")]
65 InvalidParameter(String),
66
67 #[error("Validation error: {0}")]
69 Validation(String),
70
71 #[error("IO error: {0}")]
73 Io(std::io::Error),
74
75 #[error("USB transfer error: {0}")]
77 Transfer(#[from] nusb::transfer::TransferError),
78
79 #[error("Not supported: {0}")]
81 NotSupported(String),
82
83 #[error("{0}")]
85 Other(String),
86}