use appcore_contracts::ContractError;
use appcore_core::RuntimeError;
use appcore_log::LogConfigError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AppError {
Contract(ContractError),
Runtime(RuntimeError),
ManifestIdentityMismatch,
Logging(LogConfigError),
Diagnostics(String),
Environment(String),
Capability(String),
}
impl std::fmt::Display for AppError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Contract(error) => write!(formatter, "invalid AppCore contract: {error:?}"),
Self::Runtime(error) => write!(formatter, "runtime error: {error:?}"),
Self::ManifestIdentityMismatch => {
formatter.write_str("application and deployment manifests identify different apps")
}
Self::Logging(error) => write!(formatter, "invalid logging configuration: {error:?}"),
Self::Diagnostics(error) => write!(formatter, "invalid diagnostics: {error}"),
Self::Environment(error) => write!(formatter, "invalid environment: {error}"),
Self::Capability(error) => write!(formatter, "invalid capability: {error}"),
}
}
}
impl std::error::Error for AppError {}
impl From<ContractError> for AppError {
fn from(error: ContractError) -> Self {
Self::Contract(error)
}
}
impl From<RuntimeError> for AppError {
fn from(error: RuntimeError) -> Self {
Self::Runtime(error)
}
}
impl From<LogConfigError> for AppError {
fn from(error: LogConfigError) -> Self {
Self::Logging(error)
}
}
pub type AppResult<T> = Result<T, AppError>;