feagi_structures/
error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4/// Common error type for FEAGI data operations.
5///
6/// Provides structured error handling for serialization, deserialization,
7/// validation, and internal errors across the FEAGI data processing pipeline.
8///
9/// # Examples
10/// ```
11/// use feagi_structures::FeagiDataError;
12///
13/// fn validate_count(count: u32) -> Result<(), FeagiDataError> {
14///     if count == 0 {
15///         return Err(FeagiDataError::BadParameters("Count must be > 0".into()));
16///     }
17///     Ok(())
18/// }
19///
20/// assert!(validate_count(0).is_err());
21/// assert!(validate_count(5).is_ok());
22/// ```
23#[derive(Debug)]
24pub enum FeagiDataError {
25    /// Failed to deserialize bytes into data structures
26    DeserializationError(String),
27    /// Failed to serialize data structures into bytes
28    SerializationError(String),
29    /// Invalid parameters provided to a function
30    BadParameters(String),
31    /// Error related to neuron operations
32    NeuronError(String),
33    /// Internal error indicating a bug (please report)
34    InternalError(String),
35    /// failed to process something in a const function
36    ConstError(&'static str),
37    /// Feature not yet implemented
38    NotImplemented,
39}
40
41impl Display for FeagiDataError {
42    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
43        match self {
44            FeagiDataError::DeserializationError(msg) => {
45                write!(f, "Failed to Deserialize Bytes: {}", msg)
46            }
47            FeagiDataError::SerializationError(msg) => {
48                write!(f, "Failed to Serialize Bytes: {}", msg)
49            }
50            FeagiDataError::BadParameters(msg) => write!(f, "Bad Parameters: {}", msg),
51            FeagiDataError::NeuronError(msg) => write!(f, "NeuronError: {}", msg),
52            FeagiDataError::InternalError(msg) => write!(
53                f,
54                "Internal Error, please raise an issue on Github: {}",
55                msg
56            ),
57            FeagiDataError::ConstError(msg) => write!(f, "ConstError: {}", msg),
58            FeagiDataError::NotImplemented => write!(
59                f,
60                "This function is not yet implemented! Please raise an issue on Github!"
61            ),
62        }
63    }
64}
65impl Error for FeagiDataError {}
66
67//  TODO From<> from other error types