1use std::borrow::Cow;
4use std::net::AddrParseError;
5use std::num::ParseIntError;
6use thiserror::Error;
7
8#[derive(Clone, Debug, Error)]
10#[non_exhaustive]
11pub enum Error {
12 #[error("Invalid GeoIP data file: {0}")]
14 BadFormat(Cow<'static, str>),
15
16 #[error("Unsupported country code in file: {0}")]
18 BadCountryCode(String),
19
20 #[error("The 'nowhere' country code ('??') is not supported in this context.")]
22 NowhereNotSupported,
23}
24
25impl From<ParseIntError> for Error {
26 fn from(_e: ParseIntError) -> Error {
27 Error::BadFormat("can't parse number".into())
28 }
29}
30
31impl From<AddrParseError> for Error {
32 fn from(_e: AddrParseError) -> Error {
33 Error::BadFormat("can't parse IPv6 address".into())
34 }
35}
36
37impl From<crate::dense_range_map::Error> for Error {
38 fn from(value: crate::dense_range_map::Error) -> Self {
39 Error::BadFormat(value.to_string().into())
40 }
41}