error.rs (1750B)
1 use std::fmt; 2 3 #[derive(Debug, Eq, PartialEq)] 4 pub enum Error { 5 DbOpenFailed, 6 NotFound, 7 DecodeError, 8 QueryError, 9 NoteProcessFailed, 10 TransactionFailed, 11 SubscriptionError, 12 BufferOverflow, 13 Filter(FilterError), 14 } 15 16 impl Error { 17 pub fn filter(ferr: FilterError) -> Self { 18 Error::Filter(ferr) 19 } 20 } 21 22 #[derive(Debug, Eq, PartialEq)] 23 pub enum FilterError { 24 FieldAlreadyExists, 25 FieldAlreadyStarted, 26 } 27 28 impl FilterError { 29 pub fn already_exists() -> Error { 30 Error::Filter(FilterError::FieldAlreadyExists) 31 } 32 33 pub fn already_started() -> Error { 34 Error::Filter(FilterError::FieldAlreadyStarted) 35 } 36 } 37 38 impl fmt::Display for FilterError { 39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 40 match self { 41 FilterError::FieldAlreadyExists => write!(f, "field already exists"), 42 FilterError::FieldAlreadyStarted => write!(f, "field already started"), 43 } 44 } 45 } 46 47 impl fmt::Display for Error { 48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 49 match self { 50 Error::DbOpenFailed => write!(f, "Open failed"), 51 Error::NotFound => write!(f, "Not found"), 52 Error::QueryError => write!(f, "Query failed"), 53 Error::DecodeError => write!(f, "Decode error"), 54 Error::NoteProcessFailed => write!(f, "Note process failed"), 55 Error::TransactionFailed => write!(f, "Transaction failed"), 56 Error::SubscriptionError => write!(f, "Subscription failed"), 57 Error::BufferOverflow => write!(f, "Buffer overflow"), 58 Error::Filter(filter_err) => write!(f, "Filter: {filter_err}"), 59 } 60 } 61 } 62 63 impl std::error::Error for Error {}