Skip to main content

libmaxminddb_rs/
error.rs

1//! Error types used by the crate.
2
3use std::io;
4
5/// Error returned by MMDB parsing, lookup, encoding and writing operations.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// The input does not have a valid MMDB database layout.
9    #[error("invalid MaxMind DB database: {0}")]
10    InvalidDatabase(&'static str),
11    /// The metadata section is absent, malformed, or unsupported.
12    #[error("invalid metadata: {0}")]
13    InvalidMetadata(&'static str),
14    /// A search-tree node index is outside the declared tree.
15    #[error("invalid search-tree node {0}")]
16    InvalidNode(u64),
17    /// A pointer or byte offset points outside the valid database region.
18    #[error("invalid offset {0}")]
19    InvalidOffset(usize),
20    /// An MMDB data type tag is invalid or unsupported.
21    #[error("unsupported or invalid MMDB data type {0}")]
22    InvalidDataType(u8),
23    /// The requested or declared IP version is not IPv4 or IPv6.
24    #[error("invalid IP version {0}")]
25    InvalidIpVersion(u16),
26    /// The database ended before the current value could be decoded.
27    #[error("unexpected end of input")]
28    UnexpectedEof,
29    /// A value cannot be represented by the writer.
30    #[error("encoding error: {0}")]
31    EncodingError(String),
32    /// A value cannot be decoded into the requested representation.
33    #[error("decoding error: {0}")]
34    DecodingError(String),
35    /// No network in the database matches the requested address.
36    #[error("lookup did not find a matching network")]
37    NotFound,
38    /// Defensive parser limits rejected excessively deep or large input.
39    #[error("resource limit exceeded: {0}")]
40    ResourceLimit(&'static str),
41    /// Underlying file or mapping I/O failed.
42    #[error(transparent)]
43    Io(#[from] io::Error),
44    /// Serde JSON conversion used by the convenience owned API failed.
45    #[error(transparent)]
46    SerdeJson(#[from] serde_json::Error),
47    /// A standard-library IP address string could not be parsed.
48    #[error(transparent)]
49    AddrParse(#[from] std::net::AddrParseError),
50    /// An IP network/CIDR string could not be parsed.
51    #[error(transparent)]
52    IpNet(#[from] ipnet::AddrParseError),
53}
54
55/// Crate-local result alias.
56pub type Result<T> = std::result::Result<T, Error>;