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 '{}' 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 {}