eshanized_polaris_core/
errors.rs1use std::fmt;
6
7#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum PolarisError {
11 #[error("Failed to connect to cluster: {0}")]
13 ConnectionFailed(String),
14
15 #[error("Task scheduling failed: {0}")]
17 SchedulingFailed(String),
18
19 #[error("Task execution failed: {0}")]
21 TaskExecutionFailed(String),
22
23 #[error("Task timed out after {0:?}")]
25 TaskTimeout(std::time::Duration),
26
27 #[error("Node not found: {0}")]
29 NodeNotFound(String),
30
31 #[error("Node unavailable: {0}")]
33 NodeUnavailable(String),
34
35 #[error("Invalid configuration: {0}")]
37 InvalidConfig(String),
38
39 #[error("Serialization error: {0}")]
41 SerializationError(String),
42
43 #[error("Network error: {0}")]
45 NetworkError(String),
46
47 #[error("Storage error: {0}")]
49 StorageError(String),
50
51 #[error("Authentication failed: {0}")]
53 AuthenticationFailed(String),
54
55 #[error("Authorization failed: {0}")]
57 AuthorizationFailed(String),
58
59 #[error("Resource limit exceeded: {0}")]
61 ResourceLimitExceeded(String),
62
63 #[error("Cycle detected in task dependency graph")]
65 DagCycleDetected,
66
67 #[error("Invalid task state transition from {from} to {to}")]
69 InvalidStateTransition {
70 from: String,
72 to: String,
74 },
75
76 #[error("IO error: {0}")]
78 Io(#[from] std::io::Error),
79
80 #[error("{0}")]
82 Other(String),
83}
84
85pub type PolarisResult<T> = Result<T, PolarisError>;
87
88impl PolarisError {
89 pub fn connection_failed(msg: impl fmt::Display) -> Self {
91 Self::ConnectionFailed(msg.to_string())
92 }
93
94 pub fn scheduling_failed(msg: impl fmt::Display) -> Self {
96 Self::SchedulingFailed(msg.to_string())
97 }
98
99 pub fn task_execution_failed(msg: impl fmt::Display) -> Self {
101 Self::TaskExecutionFailed(msg.to_string())
102 }
103
104 pub fn network_error(msg: impl fmt::Display) -> Self {
106 Self::NetworkError(msg.to_string())
107 }
108
109 pub fn storage_error(msg: impl fmt::Display) -> Self {
111 Self::StorageError(msg.to_string())
112 }
113
114 pub fn other(msg: impl fmt::Display) -> Self {
116 Self::Other(msg.to_string())
117 }
118}
119
120#[cfg(test)]
121mod tests {
122 use super::*;
123
124 #[test]
125 fn test_error_display() {
126 let err = PolarisError::connection_failed("test connection");
127 assert!(err.to_string().contains("test connection"));
128 }
129
130 #[test]
131 fn test_error_from_io() {
132 let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
133 let err: PolarisError = io_err.into();
134 assert!(matches!(err, PolarisError::Io(_)));
135 }
136}