use thiserror::Error;
pub type SmithyResult<T> = Result<T, SmithyError>;
#[derive(Error, Debug)]
pub enum SmithyError {
#[error("Task execution failed: {message}")]
TaskExecutionFailed {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
#[error("Task type '{task_type}' not found in registry")]
TaskNotFound {
task_type: String,
},
#[error("Serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
#[error("Queue error: {message}")]
QueueError {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
#[error("Worker operation timed out after {timeout_secs} seconds")]
Timeout {
timeout_secs: u64,
},
#[error("Configuration error: {message}")]
ConfigError {
message: String,
},
#[error("Smithy is already running")]
AlreadyRunning,
#[error("Smithy is not running")]
NotRunning,
#[cfg(feature = "redis-queue")]
#[cfg_attr(docsrs, doc(cfg(feature = "redis-queue")))]
#[error("Redis error: {0}")]
Redis(#[from] redis::RedisError),
#[cfg(feature = "postgres-queue")]
#[cfg_attr(docsrs, doc(cfg(feature = "postgres-queue")))]
#[error("Database error: {0}")]
Database(#[from] sqlx::Error),
}
impl SmithyError {
pub fn task_execution<E>(message: impl Into<String>, source: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
Self::TaskExecutionFailed {
message: message.into(),
source: Some(Box::new(source)),
}
}
pub fn queue<E>(message: impl Into<String>, source: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
Self::QueueError {
message: message.into(),
source: Some(Box::new(source)),
}
}
pub fn config(message: impl Into<String>) -> Self {
Self::ConfigError {
message: message.into(),
}
}
}