1use std::error::Error;
4use std::fmt::{Display, Formatter, Result as FormatResult};
5
6pub type ThingdResult<T> = Result<T, ThingdError>;
8
9#[derive(Clone, Debug, Eq, PartialEq)]
11pub enum ThingdError {
12 InvalidInput(String),
14 NotFound(String),
16 Conflict(String),
18 Storage(String),
20}
21
22impl Display for ThingdError {
23 fn fmt(&self, formatter: &mut Formatter<'_>) -> FormatResult {
24 match self {
25 Self::InvalidInput(message) => write!(formatter, "invalid input: {message}"),
26 Self::NotFound(message) => write!(formatter, "not found: {message}"),
27 Self::Conflict(message) => write!(formatter, "conflict: {message}"),
28 Self::Storage(message) => write!(formatter, "storage error: {message}"),
29 }
30 }
31}
32
33impl Error for ThingdError {}
34
35#[cfg(feature = "sqlite")]
36impl From<rusqlite::Error> for ThingdError {
37 fn from(error: rusqlite::Error) -> Self {
38 Self::Storage(error.to_string())
39 }
40}