Skip to main content

aura_effects/
error.rs

1//! Error types for Layer 3 effect handlers.
2//!
3//! Provides structured errors for handler failures, unsupported operations,
4//! and invalid inputs with conversion to the unified AuraError type.
5
6use aura_core::AuraError;
7
8/// Structured error type for Layer 3 handlers.
9#[derive(Debug, thiserror::Error)]
10pub enum Layer3Error {
11    /// Unsupported operation invoked through a handler.
12    #[error("Unsupported operation: {operation}")]
13    UnsupportedOperation {
14        /// Name of the unsupported operation.
15        operation: &'static str,
16    },
17
18    /// Handler failed to execute an operation.
19    #[error("Handler failure: {message}")]
20    HandlerFailure {
21        /// Failure detail for diagnostics.
22        message: String,
23    },
24
25    /// Invalid input for a handler operation.
26    #[error("Invalid input: {message}")]
27    InvalidInput {
28        /// Validation failure detail.
29        message: String,
30    },
31}
32
33impl Layer3Error {
34    /// Create an unsupported-operation error.
35    pub fn unsupported(operation: &'static str) -> Self {
36        Self::UnsupportedOperation { operation }
37    }
38
39    /// Create a handler failure error.
40    pub fn handler_failure(message: impl Into<String>) -> Self {
41        Self::HandlerFailure {
42            message: message.into(),
43        }
44    }
45
46    /// Create an invalid-input error.
47    pub fn invalid_input(message: impl Into<String>) -> Self {
48        Self::InvalidInput {
49            message: message.into(),
50        }
51    }
52}
53
54impl From<Layer3Error> for AuraError {
55    fn from(error: Layer3Error) -> Self {
56        match error {
57            Layer3Error::UnsupportedOperation { operation } => {
58                AuraError::invalid(format!("Unsupported operation: {operation}"))
59            }
60            Layer3Error::HandlerFailure { message } => AuraError::internal(message),
61            Layer3Error::InvalidInput { message } => AuraError::invalid(message),
62        }
63    }
64}