107 lines
4.0 KiB
Rust
107 lines
4.0 KiB
Rust
// Added error
|
|
// Duration is still used, Instant and sleep were removed
|
|
|
|
/// Comprehensive error type for all possible failures in the Rhai client.
|
|
///
|
|
/// This enum covers all error scenarios that can occur during client operations,
|
|
/// from Redis connectivity issues to task execution timeouts.
|
|
#[derive(Debug)]
|
|
pub enum SupervisorError {
|
|
/// Redis connection or operation error
|
|
RedisError(redis::RedisError),
|
|
/// JSON serialization/deserialization error
|
|
SerializationError(serde_json::Error),
|
|
/// Task execution timeout - contains the task_id that timed out
|
|
Timeout(String),
|
|
/// Task not found after submission - contains the task_id (rare occurrence)
|
|
TaskNotFound(String),
|
|
/// Context ID is missing
|
|
ContextIdMissing,
|
|
/// Invalid input provided
|
|
InvalidInput(String),
|
|
/// Job operation error
|
|
JobError(hero_job::JobError),
|
|
/// Actor lifecycle management errors
|
|
ActorStartFailed(String, String),
|
|
ActorStopFailed(String, String),
|
|
ActorRestartFailed(String, String),
|
|
ActorStatusFailed(String, String),
|
|
ActorNotFound(String),
|
|
PingJobFailed(String, String),
|
|
/// Zinit client operation error
|
|
ZinitError(String),
|
|
SupervisorNotConfigured,
|
|
/// Configuration file parsing error
|
|
ConfigError(String),
|
|
}
|
|
|
|
impl From<redis::RedisError> for SupervisorError {
|
|
fn from(err: redis::RedisError) -> Self {
|
|
SupervisorError::RedisError(err)
|
|
}
|
|
}
|
|
|
|
impl From<serde_json::Error> for SupervisorError {
|
|
fn from(err: serde_json::Error) -> Self {
|
|
SupervisorError::SerializationError(err)
|
|
}
|
|
}
|
|
|
|
impl From<hero_job::JobError> for SupervisorError {
|
|
fn from(err: hero_job::JobError) -> Self {
|
|
SupervisorError::JobError(err)
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for SupervisorError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
SupervisorError::RedisError(e) => write!(f, "Redis error: {}", e),
|
|
SupervisorError::SerializationError(e) => write!(f, "Serialization error: {}", e),
|
|
SupervisorError::Timeout(task_id) => {
|
|
write!(f, "Timeout waiting for task {} to complete", task_id)
|
|
}
|
|
SupervisorError::TaskNotFound(task_id) => {
|
|
write!(f, "Task {} not found after submission", task_id)
|
|
}
|
|
SupervisorError::ContextIdMissing => {
|
|
write!(f, "Context ID is missing")
|
|
}
|
|
SupervisorError::InvalidInput(msg) => {
|
|
write!(f, "Invalid input: {}", msg)
|
|
}
|
|
SupervisorError::JobError(e) => {
|
|
write!(f, "Job error: {}", e)
|
|
}
|
|
SupervisorError::ActorStartFailed(actor, reason) => {
|
|
write!(f, "Failed to start actor '{}': {}", actor, reason)
|
|
}
|
|
SupervisorError::ActorStopFailed(actor, reason) => {
|
|
write!(f, "Failed to stop actor '{}': {}", actor, reason)
|
|
}
|
|
SupervisorError::ActorRestartFailed(actor, reason) => {
|
|
write!(f, "Failed to restart actor '{}': {}", actor, reason)
|
|
}
|
|
SupervisorError::ActorStatusFailed(actor, reason) => {
|
|
write!(f, "Failed to get status for actor '{}': {}", actor, reason)
|
|
}
|
|
SupervisorError::ActorNotFound(actor) => {
|
|
write!(f, "Actor '{}' not found", actor)
|
|
}
|
|
SupervisorError::PingJobFailed(actor, reason) => {
|
|
write!(f, "Ping job failed for actor '{}': {}", actor, reason)
|
|
}
|
|
SupervisorError::ZinitError(msg) => {
|
|
write!(f, "Zinit error: {}", msg)
|
|
}
|
|
SupervisorError::SupervisorNotConfigured => {
|
|
write!(f, "Supervisor not configured for health monitoring")
|
|
}
|
|
SupervisorError::ConfigError(msg) => {
|
|
write!(f, "Configuration error: {}", msg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for SupervisorError {} |