term_guard/analyzers/
errors.rs1use thiserror::Error;
4
5pub type AnalyzerResult<T> = Result<T, AnalyzerError>;
7
8#[derive(Error, Debug)]
10pub enum AnalyzerError {
11 #[error("Failed to compute state: {0}")]
13 StateComputation(String),
14
15 #[error("Failed to compute metric: {0}")]
17 MetricComputation(String),
18
19 #[error("Failed to merge states: {0}")]
21 StateMerge(String),
22
23 #[error("Query execution failed: {0}")]
25 QueryExecution(#[from] datafusion::error::DataFusionError),
26
27 #[error("Arrow computation failed: {0}")]
29 ArrowComputation(#[from] arrow::error::ArrowError),
30
31 #[error("Invalid configuration: {0}")]
33 InvalidConfiguration(String),
34
35 #[error("Invalid data: {0}")]
37 InvalidData(String),
38
39 #[error("No data available for analysis")]
41 NoData,
42
43 #[error("Serialization error: {0}")]
45 Serialization(String),
46
47 #[error("{0}")]
49 Custom(String),
50}
51
52impl AnalyzerError {
53 pub fn state_computation(msg: impl Into<String>) -> Self {
55 Self::StateComputation(msg.into())
56 }
57
58 pub fn metric_computation(msg: impl Into<String>) -> Self {
60 Self::MetricComputation(msg.into())
61 }
62
63 pub fn state_merge(msg: impl Into<String>) -> Self {
65 Self::StateMerge(msg.into())
66 }
67
68 pub fn invalid_config(msg: impl Into<String>) -> Self {
70 Self::InvalidConfiguration(msg.into())
71 }
72
73 pub fn invalid_data(msg: impl Into<String>) -> Self {
75 Self::InvalidData(msg.into())
76 }
77
78 pub fn custom(msg: impl Into<String>) -> Self {
80 Self::Custom(msg.into())
81 }
82
83 pub fn execution(msg: impl Into<String>) -> Self {
85 Self::Custom(format!("Execution error: {}", msg.into()))
86 }
87
88 pub fn internal(msg: impl Into<String>) -> Self {
90 Self::Custom(format!("Internal error: {}", msg.into()))
91 }
92}
93
94impl From<serde_json::Error> for AnalyzerError {
96 fn from(err: serde_json::Error) -> Self {
97 Self::Serialization(err.to_string())
98 }
99}