Skip to main content

hyprstream_metrics/error/
mod.rs

1use std::error::Error;
2use std::fmt;
3
4// Wrapper for tonic::Status
5#[derive(Debug)]
6pub struct StatusWrapper(pub tonic::Status);
7
8impl Error for StatusWrapper {
9    fn source(&self) -> Option<&(dyn Error + 'static)> {
10        None
11    }
12}
13
14impl fmt::Display for StatusWrapper {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        write!(f, "{}", self.0)
17    }
18}
19
20// Wrapper for DuckDB errors
21#[derive(Debug)]
22pub struct DuckDbErrorWrapper(pub duckdb::Error);
23
24impl Error for DuckDbErrorWrapper {
25    fn source(&self) -> Option<&(dyn Error + 'static)> {
26        Some(&self.0)
27    }
28}
29
30impl fmt::Display for DuckDbErrorWrapper {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        self.0.fmt(f)
33    }
34}
35
36// Convert DuckDB error wrapper to Status
37impl From<DuckDbErrorWrapper> for tonic::Status {
38    fn from(err: DuckDbErrorWrapper) -> Self {
39        tonic::Status::internal(format!("DuckDB error: {}", err.0))
40    }
41}
42
43// Convert StatusWrapper to DataFusionError
44impl From<StatusWrapper> for datafusion::error::DataFusionError {
45    fn from(status: StatusWrapper) -> Self {
46        datafusion::error::DataFusionError::External(Box::new(status))
47    }
48}