public_ip_address/
error.rs

1//! # ❌ Crate errors
2
3use crate::lookup::error::LookupError;
4use thiserror::Error;
5
6/// Result type wrapper for the crate
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Error type for the crate
10#[derive(Error, Debug)]
11#[non_exhaustive]
12pub enum Error {
13    /// Cache error when reading or writing to the cache
14    #[error("Cache error")]
15    CacheError(#[from] CacheError),
16    /// Lookup error when fetching information about an IP address
17    #[error("Lookup error")]
18    LookupError(#[from] LookupError),
19    /// System time error, usually when converting from a timestamp
20    #[error("Time error")]
21    TimeError(#[from] std::time::SystemTimeError),
22}
23
24/// Error type for the cache module
25#[derive(Error, Debug)]
26#[non_exhaustive]
27pub enum CacheError {
28    /// Serde error when serializing or deserializing data
29    #[error("Serde error")]
30    SerdeError(#[from] serde_json::Error),
31    /// IO error when reading or writing to the cache
32    #[error("IO error")]
33    IOError(#[from] std::io::Error),
34    /// Utf8 error when converting from bytes to string
35    #[error("Utf8 error")]
36    Utf8Error(#[from] std::string::FromUtf8Error),
37    /// Encryption error when encrypting or decrypting data
38    #[error("Encryption error")]
39    EncryptionError(String),
40}