1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
use anyhow::*; use std::fmt::{Display, Formatter}; #[derive(Debug)] pub enum DataError { Anyhow(anyhow::Error), Str(String), Io(std::io::Error), RollBack, Reset, AnyNotSupported } impl Display for DataError { #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { DataError::Io(err) => Display::fmt(err, f), DataError::Str(err) => { write!(f, "DataError Str:{}", err) } DataError::Anyhow(err) => Display::fmt(err, f), DataError::RollBack=> write!(f, "RollBack"), DataError::Reset=> write!(f, "Reset"), DataError::AnyNotSupported=> write!(f, "Deserialize any not supported"), } } } impl std::error::Error for DataError {} impl serde::ser::Error for DataError { #[inline] fn custom<T>(msg: T) -> Self where T: Display, { DataError::Anyhow(anyhow!("{}", msg)) } } impl serde::de::Error for DataError { #[inline] fn custom<T>(msg: T) -> Self where T: Display, { DataError::Anyhow(anyhow!("{}", msg)) } } impl From<anyhow::Error> for DataError { #[inline] fn from(err: anyhow::Error) -> Self { DataError::Anyhow(err) } } impl From<std::io::Error> for DataError { #[inline] fn from(err: std::io::Error) -> Self { DataError::Io(err) } }