Skip to main content

capsula_core/
error.rs

1use thiserror::Error;
2
3/// Library-wide result alias
4pub type CapsulaResult<T> = Result<T, CapsulaError>;
5
6/// Core error type for the Capsula library
7///
8/// This enum defines common infrastructure errors. Hook-specific errors
9/// should be defined in their respective crates and converted to `CoreError`
10/// via the `HookFailed` variant.
11#[derive(Debug, Error)]
12pub enum CapsulaError {
13    /// I/O operation failed
14    #[error(transparent)]
15    Io(#[from] std::io::Error),
16
17    /// Serialization/deserialization failed
18    #[error("Serialization failed: {0}")]
19    Serialization(#[from] serde_json::Error),
20
21    /// Configuration-related error
22    #[error("Configuration error: {message}")]
23    Configuration { message: String },
24
25    /// Hook execution failed
26    /// This variant wraps hook-specific errors while preserving the error chain
27    #[error("Hook '{hook}' failed")]
28    HookFailed {
29        hook: String,
30        #[source]
31        source: Box<dyn std::error::Error + Send + Sync>,
32    },
33
34    /// Generic error for unexpected conditions
35    #[error("{0}")]
36    Other(String),
37}