datafake_rs/
error.rs

1//! Error types for datafake-rs operations.
2//!
3//! This module defines [`DataFakeError`], which covers all error cases
4//! that can occur during configuration parsing and data generation.
5
6use thiserror::Error;
7
8/// All possible errors that can occur in datafake-rs operations.
9#[derive(Error, Debug)]
10pub enum DataFakeError {
11    /// Failed to parse the JSON configuration.
12    #[error("Configuration parsing error: {0}")]
13    ConfigParse(String),
14
15    /// The configuration structure is invalid (e.g., null schema, empty variable names).
16    #[error("Invalid configuration structure: {0}")]
17    InvalidConfig(String),
18
19    /// A referenced variable was not found in the context.
20    #[error("Variable not found: {0}")]
21    VariableNotFound(String),
22
23    /// JSON serialization/deserialization failed.
24    #[error("JSON serialization error: {0}")]
25    JsonError(#[from] serde_json::Error),
26
27    /// An error occurred in the fake data operator.
28    #[error("Fake operator error: {0}")]
29    FakeOperatorError(String),
30
31    /// Failed to convert between types.
32    #[error("Type conversion error: {0}")]
33    TypeConversion(String),
34
35    /// The specified locale is not supported.
36    #[error("Invalid locale: {0}")]
37    InvalidLocale(String),
38
39    /// Numeric range is invalid (min > max).
40    #[error("Invalid numeric range: min={min}, max={max}")]
41    InvalidRange {
42        /// The minimum value specified.
43        min: f64,
44        /// The maximum value specified.
45        max: f64,
46    },
47}
48
49/// A specialized Result type for datafake-rs operations.
50pub type Result<T> = std::result::Result<T, DataFakeError>;