Skip to main content

datacard_rs/
error.rs

1//! Error types for DataCard operations
2
3use std::io;
4
5/// Error types for DataCard operations
6#[derive(Debug, thiserror::Error)]
7pub enum CardError {
8    #[error("IO error: {0}")]
9    Io(#[from] io::Error),
10
11    #[error("BytePunch error: {0}")]
12    BytePunch(#[from] bytepunch_rs::BytePunchError),
13
14    #[error("JSON error: {0}")]
15    Json(#[from] serde_json::Error),
16
17    #[error("Invalid magic bytes: got {0:?}")]
18    InvalidMagic([u8; 4]),
19
20    #[error("Unsupported version: {major}.{minor}")]
21    UnsupportedVersion { major: u8, minor: u8 },
22
23    #[error("Metadata too large: {0} bytes (max 65536)")]
24    MetadataTooLarge(usize),
25
26    #[error("Payload size mismatch: expected {expected}, got {actual}")]
27    PayloadSizeMismatch { expected: u64, actual: usize },
28
29    #[error("Checksum validation failed: expected {expected:08x}, got {actual:08x}")]
30    ChecksumMismatch { expected: u32, actual: u32 },
31
32    #[error("Invalid card format: {0}")]
33    InvalidFormat(String),
34}
35
36pub type Result<T> = std::result::Result<T, CardError>;