tor_geoip/
err.rs

1//! Error types for GeoIP parsing.
2
3use std::net::AddrParseError;
4use std::num::ParseIntError;
5use thiserror::Error;
6
7/// An error type from the tor-geoip crate.
8#[derive(Clone, Debug, Error)]
9#[non_exhaustive]
10pub enum Error {
11    /// The GeoIP file is formatted wrong.
12    #[error("Invalid GeoIP data file: {0}")]
13    BadFormat(&'static str),
14    /// We got a country code that isn't 2 ASCII letters.
15    #[error("Unsupported country code in file: {0}")]
16    BadCountryCode(String),
17
18    /// Tried to use ?? somewhere that expected a country code.
19    #[error("The 'nowhere' country code ('??') is not supported in this context.")]
20    NowhereNotSupported,
21}
22
23impl From<ParseIntError> for Error {
24    fn from(_e: ParseIntError) -> Error {
25        Error::BadFormat("can't parse number")
26    }
27}
28
29impl From<AddrParseError> for Error {
30    fn from(_e: AddrParseError) -> Error {
31        Error::BadFormat("can't parse IPv6 address")
32    }
33}