Skip to main content

aster_forge_config/
error.rs

1//! Error type shared by the configuration core.
2//!
3//! Product services map these errors into their own public API error codes at
4//! the boundary. The core deliberately keeps variants small and transport
5//! neutral so it can be reused by HTTP services, CLI tools, workers, and tests.
6
7/// Result type returned by configuration-core operations.
8pub type Result<T> = std::result::Result<T, ConfigCoreError>;
9
10/// Error returned by configuration-core helpers.
11#[derive(Debug, thiserror::Error)]
12pub enum ConfigCoreError {
13    /// A value failed semantic validation.
14    #[error("{0}")]
15    InvalidValue(String),
16    /// A requested key was not present in the registry.
17    #[error("unknown config key '{0}'")]
18    UnknownKey(String),
19    /// A storage backend operation failed.
20    #[error("config store operation failed: {0}")]
21    Store(String),
22    /// A notification backend operation failed.
23    #[error("config notification failed: {0}")]
24    Notification(String),
25    /// JSON serialization or deserialization failed.
26    #[error("config JSON operation failed: {0}")]
27    Json(#[from] serde_json::Error),
28}
29
30impl ConfigCoreError {
31    /// Creates an invalid-value error.
32    pub fn invalid_value(message: impl Into<String>) -> Self {
33        Self::InvalidValue(message.into())
34    }
35
36    /// Creates a storage-backend error.
37    pub fn store(message: impl Into<String>) -> Self {
38        Self::Store(message.into())
39    }
40
41    /// Creates a notification-backend error.
42    pub fn notification(message: impl Into<String>) -> Self {
43        Self::Notification(message.into())
44    }
45}