Skip to main content

xdb_parse/
error.rs

1//! Error types for the xdb-parse library.
2
3use thiserror::Error;
4
5/// All errors returned by xdb-parse operations.
6///
7/// Wraps I/O errors, parsing errors, invalid input, and corrupt data.
8/// Uses `thiserror` for automatic [`std::fmt::Display`] and [`std::error::Error`] impls.
9#[derive(Debug, Error)]
10pub enum XdbError {
11    /// The input string could not be parsed as an IP address or numeric value.
12    #[error("Invalid IP: {0}")]
13    InvalidIP(String),
14
15    /// The xdb file version could not be determined.
16    #[error("Invalid IP Version: {0}")]
17    InvalidIPVersion(String),
18
19    /// Region data in the xdb file is not valid UTF-8.
20    #[error("Invalid UTF-8 in region data")]
21    InvalidUtf8,
22
23    /// Header parsing failed.
24    #[error("Header Parse Error: {0}")]
25    HeaderParseError(String),
26
27    /// Index access out of range (corrupt or truncated file).
28    #[error("RangeIndexOut:{0}")]
29    RangeIndexOutError(String),
30
31    /// Wraps [`std::net::AddrParseError`].
32    #[error("AddrParseError: {0}")]
33    AddrParseError(#[from] std::net::AddrParseError),
34
35    /// Wraps [`std::num::ParseIntError`].
36    #[error("ParseInt Error: {0}")]
37    ParseIntError(#[from] std::num::ParseIntError),
38
39    /// Wraps [`std::io::Error`].
40    #[error("Io Error:{0}")]
41    IoError(#[from] std::io::Error),
42
43    /// Wraps [`std::array::TryFromSliceError`] — typically from corrupt data.
44    #[error("Slice Error: {0}")]
45    SliceError(#[from] std::array::TryFromSliceError),
46}