1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum GovernorError {
8 #[error("Invalid request: {0}")]
10 InvalidRequest(String),
11
12 #[error("Policy evaluation failed: {0}")]
14 EvaluationFailed(String),
15
16 #[error("Invalid degradation threshold: {0}")]
18 InvalidThreshold(String),
19
20 #[error("Unsupported content type: {0}")]
22 UnsupportedContentType(String),
23
24 #[error("Internal error: {0}")]
26 Internal(String),
27}
28
29impl GovernorError {
30 pub fn is_recoverable(&self) -> bool {
32 matches!(
33 self,
34 GovernorError::InvalidThreshold(_) | GovernorError::UnsupportedContentType(_)
35 )
36 }
37
38 pub fn is_configuration_error(&self) -> bool {
40 matches!(
41 self,
42 GovernorError::InvalidThreshold(_) | GovernorError::Internal(_)
43 )
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn error_recoverability() {
53 let err = GovernorError::InvalidThreshold("too high".to_string());
54 assert!(err.is_recoverable());
55
56 let err = GovernorError::Internal("bug".to_string());
57 assert!(!err.is_recoverable());
58 }
59
60 #[test]
61 fn error_display() {
62 let err = GovernorError::InvalidRequest("bad value".to_string());
63 assert_eq!(err.to_string(), "Invalid request: bad value");
64 }
65}