Skip to main content

ash_flare/supervisor/
error.rs

1//! Supervisor errors
2
3use std::fmt;
4
5/// Errors returned by supervisor operations.
6#[derive(Debug, Clone)]
7pub enum SupervisorError {
8    /// Supervisor has no children
9    NoChildren(String),
10    /// All children have failed
11    AllChildrenFailed(String),
12    /// Supervisor is shutting down
13    ShuttingDown(String),
14    /// Child with this ID already exists
15    ChildAlreadyExists(String),
16    /// Child with this ID not found
17    ChildNotFound(String),
18    /// Child initialization failed
19    InitializationFailed {
20        /// ID of the child that failed to initialize
21        child_id: String,
22        /// Reason for initialization failure
23        reason: String,
24    },
25    /// Child initialization timed out
26    InitializationTimeout {
27        /// ID of the child that timed out
28        child_id: String,
29        /// Duration after which timeout occurred
30        timeout: std::time::Duration,
31    },
32}
33
34impl fmt::Display for SupervisorError {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            SupervisorError::NoChildren(name) => {
38                write!(f, "supervisor '{}' has no children", name)
39            }
40            SupervisorError::AllChildrenFailed(name) => {
41                write!(
42                    f,
43                    "all children failed for supervisor '{}' - restart intensity limit exceeded",
44                    name
45                )
46            }
47            SupervisorError::ShuttingDown(name) => {
48                write!(
49                    f,
50                    "supervisor '{}' is shutting down - operation not permitted",
51                    name
52                )
53            }
54            SupervisorError::ChildAlreadyExists(id) => {
55                write!(
56                    f,
57                    "child with id '{}' already exists - use a unique identifier",
58                    id
59                )
60            }
61            SupervisorError::ChildNotFound(id) => {
62                write!(
63                    f,
64                    "child with id '{}' not found - it may have already terminated",
65                    id
66                )
67            }
68            SupervisorError::InitializationFailed { child_id, reason } => {
69                write!(f, "child '{}' initialization failed: {}", child_id, reason)
70            }
71            SupervisorError::InitializationTimeout { child_id, timeout } => {
72                write!(
73                    f,
74                    "child '{}' initialization timed out after {:?}",
75                    child_id, timeout
76                )
77            }
78        }
79    }
80}
81
82impl std::error::Error for SupervisorError {}