1use appcore_contracts::ContractError;
14use appcore_core::RuntimeError;
15use appcore_log::LogConfigError;
16
17#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum AppError {
20 Contract(ContractError),
22 Runtime(RuntimeError),
24 ManifestIdentityMismatch,
26 Logging(LogConfigError),
28 Diagnostics(String),
30 Environment(String),
32 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
72pub type AppResult<T> = Result<T, AppError>;