Skip to main content

inspect_core/
error.rs

1//! Error types for inspection.
2
3#[cfg(not(feature = "std"))]
4use alloc::string::String;
5use core::fmt;
6
7/// Result type for inspection operations.
8pub type InspectResult<T> = Result<T, InspectError>;
9
10/// Errors that can occur during inspection.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum InspectError {
13    /// A configured limit was exceeded.
14    LimitExceeded(String),
15
16    /// The requested path does not exist.
17    InvalidPath(String),
18
19    /// The value kind does not support the requested operation.
20    UnsupportedOperation(String),
21
22    /// A cycle was detected in the value graph.
23    CycleDetected,
24
25    /// A custom error from a user implementation.
26    Custom(String),
27}
28
29impl fmt::Display for InspectError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            InspectError::LimitExceeded(msg) => write!(f, "Limit exceeded: {}", msg),
33            InspectError::InvalidPath(msg) => write!(f, "Invalid path: {}", msg),
34            InspectError::UnsupportedOperation(msg) => {
35                write!(f, "Unsupported operation: {}", msg)
36            }
37            InspectError::CycleDetected => write!(f, "Cycle detected"),
38            InspectError::Custom(msg) => write!(f, "{}", msg),
39        }
40    }
41}
42
43#[cfg(feature = "std")]
44impl std::error::Error for InspectError {}