use core::fmt;
use alloc::string::String;
#[derive(Debug)]
pub enum ProductOSServerError {
GenericError(String),
InitializationError {
reason: String,
},
ConfigurationError {
component: String,
message: String,
},
#[cfg(feature = "controller")]
ControllerError {
operation: String,
message: String,
},
CertificateError {
message: String,
},
ExecutorError {
message: String,
},
#[cfg(feature = "controller")]
StoreError {
store_type: String,
message: String,
},
Timeout {
operation: String,
},
LockError {
resource: String,
},
}
impl fmt::Display for ProductOSServerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::GenericError(msg) => write!(f, "Server error: {}", msg),
Self::InitializationError { reason } => {
write!(f, "Failed to initialize server: {}", reason)
}
Self::ConfigurationError { component, message } => {
write!(f, "Configuration error in {}: {}", component, message)
}
#[cfg(feature = "controller")]
Self::ControllerError { operation, message } => {
write!(f, "Controller error during {}: {}", operation, message)
}
Self::CertificateError { message } => {
write!(f, "Certificate error: {}", message)
}
Self::ExecutorError { message } => {
write!(f, "Executor error: {}", message)
}
#[cfg(feature = "controller")]
Self::StoreError { store_type, message } => {
write!(f, "{} store error: {}", store_type, message)
}
Self::Timeout { operation } => {
write!(f, "Operation timed out: {}", operation)
}
Self::LockError { resource } => {
write!(f, "Failed to acquire lock on: {}", resource)
}
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ProductOSServerError {}
pub type Result<T> = core::result::Result<T, ProductOSServerError>;