1use std::error::Error;
4use std::fmt::Display;
5use std::path::PathBuf;
6
7#[derive(Debug)]
11pub enum TransientError {
12 IncretmentError,
14 ParsingToByteError,
16 ParsingToUTF8Error,
18 SledError {
20 error: sled::Error
22 },
23 SledTransactionError,
25 ParsingToU64ByteFailed,
27 FolderNotFound { path: PathBuf },
29 ZipError {
31 error: zip::result::ZipError
33 },
34 FileNameDoesntExist,
36 MetadataNotFound,
38 DBMetadataNotFound,
40 PoisonedMutex,
42 ParsingFromByteError,
44 IOError {
46 error: std::io::Error
48 }
49}
50
51impl Display for TransientError {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 match self {
54 TransientError::IncretmentError => writeln!(f, "Incretment has failed"),
55 TransientError::ParsingToByteError => writeln!(f, "Parsing to byte failed"),
56 TransientError::ParsingToUTF8Error => writeln!(f, "Parsing to utf8 failed"),
57 TransientError::SledError {
58 error
59 } => writeln!(f, "Sled failed {error}"),
60 TransientError::SledTransactionError => writeln!(f, "Sled Transaction failed"),
61 TransientError::ParsingToU64ByteFailed => {
62 writeln!(f, "Failed to parse a variable to a U64 byte [u8; 8]")
63 },
64 TransientError::FolderNotFound {
65 path
66 } => {
67 writeln!(f, "Folder is not found at the path: {path:#?}")
68 },
69 TransientError::ZipError {
70 error
71 } => writeln!(f, "Zip crate failed {error}"),
72 TransientError::FileNameDoesntExist => writeln!(f, "File name doesnt exist"),
73 TransientError::MetadataNotFound => writeln!(f, "Metadata is not found"),
74 TransientError::DBMetadataNotFound => writeln!(f, "DB metadata is not found"),
75 TransientError::PoisonedMutex => writeln!(f, "Mutex is poisoned"),
76 TransientError::ParsingFromByteError => writeln!(f, "Partsing from byte failed"),
77 TransientError::IOError {
78 error
79 } => writeln!(f, "std IO failed {error}")
80 }
81 }
82}
83
84impl Error for TransientError {}