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 '{name}' has no children")
39            }
40            SupervisorError::AllChildrenFailed(name) => {
41                write!(
42                    f,
43                    "all children failed for supervisor '{name}' - restart intensity limit exceeded"
44                )
45            }
46            SupervisorError::ShuttingDown(name) => {
47                write!(
48                    f,
49                    "supervisor '{name}' is shutting down - operation not permitted"
50                )
51            }
52            SupervisorError::ChildAlreadyExists(id) => {
53                write!(
54                    f,
55                    "child with id '{id}' already exists - use a unique identifier"
56                )
57            }
58            SupervisorError::ChildNotFound(id) => {
59                write!(
60                    f,
61                    "child with id '{id}' not found - it may have already terminated"
62                )
63            }
64            SupervisorError::InitializationFailed { child_id, reason } => {
65                write!(f, "child '{child_id}' initialization failed: {reason}")
66            }
67            SupervisorError::InitializationTimeout { child_id, timeout } => {
68                write!(
69                    f,
70                    "child '{child_id}' initialization timed out after {timeout:?}"
71                )
72            }
73        }
74    }
75}
76
77impl std::error::Error for SupervisorError {}