Skip to main content

graphrecords_overview/
error.rs

1use graphrecords_core::errors::GraphRecordError;
2use graphrecords_query::Failure;
3use std::{
4    error::Error,
5    fmt::{Display, Formatter, Result as FmtResult},
6};
7
8pub type OverviewResult<T> = Result<T, OverviewError>;
9
10#[derive(Debug)]
11pub enum OverviewError {
12    GraphRecord(GraphRecordError),
13    Query(Box<Failure>),
14}
15
16impl Error for OverviewError {
17    fn source(&self) -> Option<&(dyn Error + 'static)> {
18        match self {
19            Self::GraphRecord(error) => Some(error),
20            Self::Query(failure) => Some(failure),
21        }
22    }
23}
24
25impl From<GraphRecordError> for OverviewError {
26    fn from(error: GraphRecordError) -> Self {
27        Self::GraphRecord(error)
28    }
29}
30
31impl From<Box<Failure>> for OverviewError {
32    fn from(failure: Box<Failure>) -> Self {
33        Self::Query(failure)
34    }
35}
36
37impl Display for OverviewError {
38    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
39        match self {
40            Self::GraphRecord(error) => write!(f, "{error}"),
41            Self::Query(failure) => write!(f, "{failure}"),
42        }
43    }
44}