Skip to main content

appcore_sdk/
error.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: error.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: 2026/09/04 00:00:00 by dnettoRaw
7//    ##   ## ##   ##    U: 2026/09/04 00:00:00 by dnettoRaw
8//      ###########      S: 1.0.0-rc.1
9// =============================================================================
10
11//! Errors returned by `SDK` setup and zero-configuration manifest synthesis.
12
13use appcore_contracts::ContractError;
14use appcore_core::RuntimeError;
15use appcore_log::LogConfigError;
16
17/// Error returned by application-facing `SDK` operations.
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum AppError {
20    /// A canonical `AppCore` contract was invalid.
21    Contract(ContractError),
22    /// A Runtime identifier or application callback was rejected.
23    Runtime(RuntimeError),
24    /// Explicit manifests describe different applications.
25    ManifestIdentityMismatch,
26    /// Explicit logger destinations or limits were invalid.
27    Logging(LogConfigError),
28    /// A diagnostic bundle field or serialization operation was invalid.
29    Diagnostics(String),
30    /// A unified SDK environment profile was invalid.
31    Environment(String),
32    /// A capability declaration or command mapping was invalid.
33    Capability(String),
34}
35
36impl std::fmt::Display for AppError {
37    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        match self {
39            Self::Contract(error) => write!(formatter, "invalid AppCore contract: {error:?}"),
40            Self::Runtime(error) => write!(formatter, "runtime error: {error:?}"),
41            Self::ManifestIdentityMismatch => {
42                formatter.write_str("application and deployment manifests identify different apps")
43            }
44            Self::Logging(error) => write!(formatter, "invalid logging configuration: {error:?}"),
45            Self::Diagnostics(error) => write!(formatter, "invalid diagnostics: {error}"),
46            Self::Environment(error) => write!(formatter, "invalid environment: {error}"),
47            Self::Capability(error) => write!(formatter, "invalid capability: {error}"),
48        }
49    }
50}
51
52impl std::error::Error for AppError {}
53
54impl From<ContractError> for AppError {
55    fn from(error: ContractError) -> Self {
56        Self::Contract(error)
57    }
58}
59
60impl From<RuntimeError> for AppError {
61    fn from(error: RuntimeError) -> Self {
62        Self::Runtime(error)
63    }
64}
65
66impl From<LogConfigError> for AppError {
67    fn from(error: LogConfigError) -> Self {
68        Self::Logging(error)
69    }
70}
71
72/// Result used by application-facing `SDK` operations.
73pub type AppResult<T> = Result<T, AppError>;