async_sqlite/
error.rs

1/// Enum of all possible errors.
2#[derive(Debug)]
3#[non_exhaustive]
4pub enum Error {
5    /// Indicates that the connection to the sqlite database is closed.
6    Closed,
7    /// Error updating PRAGMA.
8    PragmaUpdate {
9        name: &'static str,
10        exp: &'static str,
11        got: String,
12    },
13    /// Represents a [`rusqlite::Error`].
14    Rusqlite(rusqlite::Error),
15}
16
17impl std::error::Error for Error {
18    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
19        match self {
20            Error::Rusqlite(err) => Some(err),
21            _ => None,
22        }
23    }
24}
25
26impl std::fmt::Display for Error {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            Error::Closed => write!(f, "connection to sqlite database closed"),
30            Error::PragmaUpdate { exp, got, name } => {
31                write!(f, "updating pragma {name}: expected '{exp}', got '{got}'")
32            }
33            Error::Rusqlite(err) => err.fmt(f),
34        }
35    }
36}
37
38impl From<rusqlite::Error> for Error {
39    fn from(value: rusqlite::Error) -> Self {
40        Error::Rusqlite(value)
41    }
42}
43
44impl<T> From<crossbeam_channel::SendError<T>> for Error {
45    fn from(_value: crossbeam_channel::SendError<T>) -> Self {
46        Error::Closed
47    }
48}
49
50impl From<crossbeam_channel::RecvError> for Error {
51    fn from(_value: crossbeam_channel::RecvError) -> Self {
52        Error::Closed
53    }
54}
55
56impl From<futures_channel::oneshot::Canceled> for Error {
57    fn from(_value: futures_channel::oneshot::Canceled) -> Self {
58        Error::Closed
59    }
60}