Skip to main content

vin_decode/
error.rs

1use thiserror::Error;
2
3/// Specialized [`Result`] alias used throughout the crate.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Errors produced during VIN parsing and decoding.
7#[derive(Debug, Error)]
8pub enum Error {
9    /// VIN length isn't 17.
10    #[error("VIN must be 17 chars, got {0}")]
11    InvalidLength(usize),
12
13    /// VIN contains a forbidden character (`I`, `O`, or `Q`).
14    #[error("VIN contains forbidden char `{0}` (I, O, Q not allowed)")]
15    ForbiddenChar(char),
16
17    /// VIN contains a non-ASCII-alphanumeric character.
18    #[error("VIN contains non-ascii-alnum char `{0}`")]
19    InvalidChar(char),
20
21    /// Computed check digit doesn't match the one in the VIN.
22    #[error("check digit mismatch: expected `{expected}`, got `{actual}`")]
23    BadCheckDigit {
24        /// Check digit computed from the VIN body.
25        expected: char,
26        /// Check digit found at position 9 of the VIN.
27        actual: char,
28    },
29
30    /// WMI prefix has no entry in the lookup tables.
31    #[error("unknown WMI: `{0}`")]
32    UnknownWmi(String),
33
34    /// Year code at position 10 isn't a valid model-year code.
35    #[error("unreadable model year (code `{0}`)")]
36    UnreadableYear(char),
37
38    /// Required data file couldn't be opened.
39    #[error("map data missing at `{0}`")]
40    MissingData(String),
41
42    /// Wraps underlying I/O errors.
43    #[error(transparent)]
44    Io(#[from] std::io::Error),
45}