use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("USB error: {0}")]
Usb(#[from] nusb::Error),
#[error("Programmer not found. Is the CH341A connected?")]
ProgrammerNotFound,
#[error("Flash chip not detected. Check connections and power.")]
FlashNotDetected,
#[error("Unsupported flash chip: JEDEC ID = {0:02X} {1:02X} {2:02X}")]
UnsupportedChip(u8, u8, u8),
#[error(
"Verification failed at address 0x{address:08X}: expected {expected:02X}, got {actual:02X}"
)]
VerificationFailed {
address: u32,
expected: u8,
actual: u8,
},
#[error("Erase failed at block {block}")]
EraseFailed { block: u32 },
#[error("Write failed at address 0x{address:08X}")]
WriteFailed { address: u32 },
#[error("Read failed at address 0x{address:08X}")]
ReadFailed { address: u32 },
#[error("Uncorrectable ECC error at address 0x{address:08X}")]
EccError { address: u32 },
#[error("Bad block detected at block {block}")]
BadBlock { block: u32 },
#[error("Operation timed out")]
Timeout,
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("IO error: {0}")]
Io(std::io::Error),
#[error("USB transfer error: {0}")]
Transfer(#[from] nusb::transfer::TransferError),
#[error("Not supported: {0}")]
NotSupported(String),
#[error("{0}")]
Other(String),
}