wip
This commit is contained in:
102
core/supervisor/src/error.rs
Normal file
102
core/supervisor/src/error.rs
Normal file
@@ -0,0 +1,102 @@
|
||||
// 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),
|
||||
/// Worker lifecycle management errors
|
||||
WorkerStartFailed(String, String),
|
||||
WorkerStopFailed(String, String),
|
||||
WorkerRestartFailed(String, String),
|
||||
WorkerStatusFailed(String, String),
|
||||
WorkerNotFound(String),
|
||||
PingJobFailed(String, String),
|
||||
/// Zinit client operation error
|
||||
ZinitError(String),
|
||||
SupervisorNotConfigured,
|
||||
}
|
||||
|
||||
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::WorkerStartFailed(worker, reason) => {
|
||||
write!(f, "Failed to start worker '{}': {}", worker, reason)
|
||||
}
|
||||
SupervisorError::WorkerStopFailed(worker, reason) => {
|
||||
write!(f, "Failed to stop worker '{}': {}", worker, reason)
|
||||
}
|
||||
SupervisorError::WorkerRestartFailed(worker, reason) => {
|
||||
write!(f, "Failed to restart worker '{}': {}", worker, reason)
|
||||
}
|
||||
SupervisorError::WorkerStatusFailed(worker, reason) => {
|
||||
write!(f, "Failed to get status for worker '{}': {}", worker, reason)
|
||||
}
|
||||
SupervisorError::WorkerNotFound(worker) => {
|
||||
write!(f, "Worker '{}' not found", worker)
|
||||
}
|
||||
SupervisorError::PingJobFailed(worker, reason) => {
|
||||
write!(f, "Ping job failed for worker '{}': {}", worker, reason)
|
||||
}
|
||||
SupervisorError::ZinitError(msg) => {
|
||||
write!(f, "Zinit error: {}", msg)
|
||||
}
|
||||
SupervisorError::SupervisorNotConfigured => {
|
||||
write!(f, "Supervisor not configured for health monitoring")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for SupervisorError {}
|
Reference in New Issue
Block a user