postit/core/
error.rs

1//! Defines errors related to file management.
2
3use thiserror::Error;
4
5/// Convenience type for database related operations.
6pub type Result<T> = std::result::Result<T, self::Error>;
7
8/// Errors related to file and path management.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Used for config related [errors][`crate::config::Error`].
12    #[error("{0}")]
13    Config(#[from] crate::config::Error),
14
15    /// Used for file system related [errors][`crate::fs::Error`].
16    #[error("{0}")]
17    Fs(#[from] crate::fs::Error),
18
19    /// Used for database related [errors][`crate::fs::Error`].
20    #[error("{0}")]
21    Db(#[from] crate::db::Error),
22
23    /// Used for I/O errors ([`std::io::Error`]).
24    #[error("{0}")]
25    Io(#[from] std::io::Error),
26
27    /// Any error that doesn't belong into the previous variants.
28    #[error("{0}")]
29    Other(#[from] Box<dyn std::error::Error + Send + Sync>),
30}
31
32impl Error {
33    /// Wraps any error-like value into [`Error::Other`].
34    #[inline]
35    pub fn wrap<E>(err: E) -> Self
36    where
37        E: Into<Box<dyn std::error::Error + Send + Sync>>,
38    {
39        Self::Other(err.into())
40    }
41}