essential_builder_db/
error.rs

1use thiserror::Error;
2
3/// Any error that might occur during builder DB connection pool access.
4#[cfg(feature = "pool")]
5#[derive(Debug, Error)]
6pub enum AcquireThenError<E> {
7    /// Failed to acquire a DB connection.
8    #[error("failed to acquire a DB connection: {0}")]
9    Acquire(#[from] tokio::sync::AcquireError),
10    /// The tokio spawn blocking task failed to join.
11    #[error("failed to join task: {0}")]
12    Join(#[from] tokio::task::JoinError),
13    /// The error returned by the `acquire_then` function result.
14    #[error("{0}")]
15    Inner(E),
16}
17
18/// An `acquire_then` error whose function returns a result with a rusqlite error.
19#[cfg(feature = "pool")]
20pub type AcquireThenRusqliteError = AcquireThenError<rusqlite::Error>;
21
22/// An `acquire_then` error whose function returns a result with a query error.
23#[cfg(feature = "pool")]
24pub type AcquireThenQueryError = AcquireThenError<crate::error::QueryError>;
25
26/// Any error that might occur during decoding of a type returned by the DB.
27#[derive(Debug, Error)]
28#[error("decoding failed due to postcard deserialization error: {0}")]
29pub struct DecodeError(#[from] pub postcard::Error);
30
31/// A database or decoding error returned by a query.
32#[derive(Debug, Error)]
33pub enum QueryError {
34    /// A DB error occurred.
35    #[error("a DB error occurred: {0}")]
36    Rusqlite(#[from] rusqlite::Error),
37    /// A decoding error occurred.
38    #[error("failed to decode: {0}")]
39    Decode(#[from] DecodeError),
40}
41
42/// One or more connections failed to close when calling [`crate::pool::ConnectionPool::close`].
43#[derive(Debug, Error)]
44pub struct ConnectionCloseErrors(pub Vec<(rusqlite::Connection, rusqlite::Error)>);
45
46impl core::fmt::Display for ConnectionCloseErrors {
47    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
48        writeln!(f, "failed to close one or more connections:")?;
49        for (ix, (_conn, err)) in self.0.iter().enumerate() {
50            writeln!(f, "  {ix}: {err}")?;
51        }
52        Ok(())
53    }
54}