ash_flare/supervisor/
error.rs

1//! Supervisor errors
2
3use std::fmt;
4
5/// Errors returned by supervisor operations.
6#[derive(Debug)]
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}
19
20impl fmt::Display for SupervisorError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            SupervisorError::NoChildren(name) => {
24                write!(f, "supervisor '{}' has no children", name)
25            }
26            SupervisorError::AllChildrenFailed(name) => {
27                write!(
28                    f,
29                    "all children failed for supervisor '{}' - restart intensity limit exceeded",
30                    name
31                )
32            }
33            SupervisorError::ShuttingDown(name) => {
34                write!(
35                    f,
36                    "supervisor '{}' is shutting down - operation not permitted",
37                    name
38                )
39            }
40            SupervisorError::ChildAlreadyExists(id) => {
41                write!(
42                    f,
43                    "child with id '{}' already exists - use a unique identifier",
44                    id
45                )
46            }
47            SupervisorError::ChildNotFound(id) => {
48                write!(
49                    f,
50                    "child with id '{}' not found - it may have already terminated",
51                    id
52                )
53            }
54        }
55    }
56}
57
58impl std::error::Error for SupervisorError {}