ash_flare/supervisor/
error.rs1use std::fmt;
4
5#[derive(Debug, Clone)]
7pub enum SupervisorError {
8 NoChildren(String),
10 AllChildrenFailed(String),
12 ShuttingDown(String),
14 ChildAlreadyExists(String),
16 ChildNotFound(String),
18 InitializationFailed {
20 child_id: String,
22 reason: String,
24 },
25 InitializationTimeout {
27 child_id: String,
29 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 {}