1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, JMapError>;
5
6#[derive(Error, Debug)]
8pub enum JMapError {
9 #[error("Invalid field type ID: 0x{0:02X}")]
11 InvalidFieldType(u8),
12
13 #[error("Field not found: {0}")]
15 FieldNotFound(String),
16
17 #[error("Field already exists: {0}")]
19 FieldAlreadyExists(String),
20
21 #[error("Type mismatch: expected {expected}, got {got}")]
23 TypeMismatch {
24 expected: &'static str,
25 got: &'static str,
26 },
27
28 #[error("Entry index out of bounds: {index} (len: {len})")]
30 EntryIndexOutOfBounds { index: usize, len: usize },
31
32 #[error("Buffer too small: expected at least {expected} bytes, got {got}")]
34 BufferTooSmall { expected: usize, got: usize },
35
36 #[error("Invalid BCSV header")]
38 InvalidHeader,
39
40 #[error("String encoding error: {0}")]
42 EncodingError(String),
43
44 #[error("CSV error: {0}")]
46 CsvError(String),
47
48 #[error("I/O error: {0}")]
50 IoError(#[from] std::io::Error),
51
52 #[error("Lookup file not found: {0}")]
54 LookupFileNotFound(String),
55
56 #[error("Invalid CSV field descriptor: {0}")]
58 InvalidCsvFieldDescriptor(String),
59}
60
61impl From<csv::Error> for JMapError {
62 fn from(err: csv::Error) -> Self {
63 JMapError::CsvError(err.to_string())
64 }
65}