nander_rs/
error.rs

1//! Error types for nander-rs
2//!
3//! This module defines all error types used throughout the library.
4
5use thiserror::Error;
6
7/// Result type alias using our Error type
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Main error type for nander-rs
11#[derive(Error, Debug)]
12pub enum Error {
13    /// USB communication error
14    #[error("USB error: {0}")]
15    Usb(#[from] nusb::Error),
16
17    /// Programmer not found
18    #[error("Programmer not found. Is the CH341A connected?")]
19    ProgrammerNotFound,
20
21    /// Flash chip not detected
22    #[error("Flash chip not detected. Check connections and power.")]
23    FlashNotDetected,
24
25    /// Unsupported flash chip
26    #[error("Unsupported flash chip: JEDEC ID = {0:02X} {1:02X} {2:02X}")]
27    UnsupportedChip(u8, u8, u8),
28
29    /// Verification failed
30    #[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    /// Erase failed
40    #[error("Erase failed at block {block}")]
41    EraseFailed { block: u32 },
42
43    /// Write failed
44    #[error("Write failed at address 0x{address:08X}")]
45    WriteFailed { address: u32 },
46
47    /// Read failed
48    #[error("Read failed at address 0x{address:08X}")]
49    ReadFailed { address: u32 },
50
51    /// ECC error (uncorrectable)
52    #[error("Uncorrectable ECC error at address 0x{address:08X}")]
53    EccError { address: u32 },
54
55    /// Bad block detected
56    #[error("Bad block detected at block {block}")]
57    BadBlock { block: u32 },
58
59    /// Timeout error
60    #[error("Operation timed out")]
61    Timeout,
62
63    /// Invalid parameter
64    #[error("Invalid parameter: {0}")]
65    InvalidParameter(String),
66
67    /// Validation error
68    #[error("Validation error: {0}")]
69    Validation(String),
70
71    /// IO error
72    #[error("IO error: {0}")]
73    Io(std::io::Error),
74
75    /// Transfer error (raw USB)
76    #[error("USB transfer error: {0}")]
77    Transfer(#[from] nusb::transfer::TransferError),
78
79    /// Feature not supported
80    #[error("Not supported: {0}")]
81    NotSupported(String),
82
83    /// Miscellaneous error
84    #[error("{0}")]
85    Other(String),
86}