1use rustfs_targets::{TargetError, arn::TargetID};
16use std::io;
17use thiserror::Error;
18use tokio::task::JoinError;
19
20#[derive(Debug, Error)]
22pub enum LifecycleError {
23 #[error("System has already been initialized")]
25 AlreadyInitialized,
26
27 #[error("System has not been initialized")]
29 NotInitialized,
30}
31
32#[derive(Debug, Error)]
34pub enum NotificationError {
35 #[error("Target error: {0}")]
36 Target(#[from] TargetError),
37
38 #[error("Configuration error: {0}")]
39 Configuration(String),
40
41 #[error("ARN not found: {0}")]
42 ARNNotFound(String),
43
44 #[error("Invalid ARN: {0}")]
45 InvalidARN(String),
46
47 #[error("Bucket notification error: {0}")]
48 BucketNotification(String),
49
50 #[error("Rule configuration error: {0}")]
51 RuleConfiguration(String),
52
53 #[error("System lifecycle error: {0}")]
54 Lifecycle(#[from] LifecycleError),
55
56 #[error("I/O error: {0}")]
57 Io(io::Error),
58
59 #[error("Failed to read configuration: {0}")]
60 ReadConfig(String),
61
62 #[error("Failed to save configuration: {0}")]
63 SaveConfig(String),
64
65 #[error("Target '{0}' not found")]
66 TargetNotFound(TargetID),
67
68 #[error("System initialization error: {0}")]
69 Initialization(String),
70
71 #[error("Storage not available: {0}")]
72 StorageNotAvailable(String),
73}
74
75pub(crate) fn transition_join_error(error: JoinError) -> NotificationError {
76 let reason = if error.is_cancelled() { "cancelled" } else { "panicked" };
77 NotificationError::Initialization(format!("Notification lifecycle transition task {reason}"))
78}
79
80#[cfg(test)]
81mod tests {
82 use super::transition_join_error;
83
84 #[tokio::test]
85 async fn transition_join_error_does_not_expose_panic_payload() {
86 let join_error = tokio::spawn(async { panic!("do-not-expose-payload") })
87 .await
88 .expect_err("test task should panic");
89
90 let rendered = transition_join_error(join_error).to_string();
91 assert!(rendered.contains("panicked"));
92 assert!(!rendered.contains("do-not-expose-payload"));
93 }
94}