tinydb/
error.rs

1//! Contains various items related to errors inside of TinyDB.
2
3/// An error enum for the possible faliure states of the [crate::Database] structure.
4#[derive(Debug)]
5pub enum DatabaseError {
6    /// When the item queried for was not found
7    ItemNotFound,
8
9    /// A duplicate value was found when adding to the database with
10    /// [crate::Database::strict_dupes] allowed.
11    DupeFound,
12    /// When [crate::Database::save_path] is required but is not found. This commonly
13    /// happens when loading or dumping a database with [crate::Database::save_path]
14    /// being [Option::None].
15    SavePathRequired,
16
17    /// Misc [std::io::Error] that could not be properly handled.
18    IOError(std::io::Error),
19
20    /// When the database could not be found. This is typically raised inside of
21    /// [crate::Database::from] when it tries to retrieve the path to the database.
22    DatabaseNotFound,
23
24    /// When the given database name to an assumption-making function like
25    /// [crate::Database::auto_from] does not have a valid file stem or could not
26    /// convert from an [std::ffi::OsString] to a [String].
27    BadDbName,
28}
29
30impl From<std::io::Error> for DatabaseError {
31    fn from(e: std::io::Error) -> Self {
32        DatabaseError::IOError(e)
33    }
34}