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: {message}")]
28 HookFailed {
29 hook: String,
30 message: String,
31 #[source]
32 source: Box<dyn std::error::Error + Send + Sync>,
33 },
34
35 /// Generic error for unexpected conditions
36 #[error("{0}")]
37 Other(String),
38}