Skip to main content

faker_rust/
error.rs

1//! Error types for Faker-Rust
2
3use std::fmt;
4
5#[derive(Debug, Clone)]
6pub enum FakerError {
7    /// Locale not found
8    LocaleNotFound(String),
9    /// Data not found
10    DataNotFound(String),
11    /// Unique generator exhausted
12    UniqueGeneratorExhausted(usize),
13    /// Invalid argument
14    InvalidArgument(String),
15    /// Random number generation error
16    RandError(String),
17}
18
19impl fmt::Display for FakerError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            FakerError::LocaleNotFound(locale) => write!(f, "Locale not found: {}", locale),
23            FakerError::DataNotFound(key) => write!(f, "Data not found: {}", key),
24            FakerError::UniqueGeneratorExhausted(retries) => {
25                write!(f, "Unique generator exhausted after {} retries", retries)
26            }
27            FakerError::InvalidArgument(msg) => write!(f, "Invalid argument: {}", msg),
28            FakerError::RandError(msg) => write!(f, "Random error: {}", msg),
29        }
30    }
31}
32
33impl std::error::Error for FakerError {}