#[derive(Debug, thiserror::Error)]
pub enum CanvasError {
#[error("Invalid workflow: {0}")]
Invalid(String),
#[error("Broker error: {0}")]
Broker(String),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Workflow cancelled: {0}")]
Cancelled(String),
#[error("Workflow timeout: {0}")]
Timeout(String),
}
impl CanvasError {
pub fn is_invalid(&self) -> bool {
matches!(self, CanvasError::Invalid(_))
}
pub fn is_broker(&self) -> bool {
matches!(self, CanvasError::Broker(_))
}
pub fn is_serialization(&self) -> bool {
matches!(self, CanvasError::Serialization(_))
}
pub fn is_cancelled(&self) -> bool {
matches!(self, CanvasError::Cancelled(_))
}
pub fn is_timeout(&self) -> bool {
matches!(self, CanvasError::Timeout(_))
}
pub fn is_retryable(&self) -> bool {
matches!(self, CanvasError::Broker(_))
}
pub fn category(&self) -> &'static str {
match self {
CanvasError::Invalid(_) => "invalid",
CanvasError::Broker(_) => "broker",
CanvasError::Serialization(_) => "serialization",
CanvasError::Cancelled(_) => "cancelled",
CanvasError::Timeout(_) => "timeout",
}
}
}