epoch_db/db/
errors.rs

1//! This module defines the custom error types used throughout the TransientDB library.
2use std::{error::Error, fmt::Display};
3
4/// The primary error enum for the TransientDB library.
5#[derive(Debug)]
6pub enum TransientError {
7    /// Error that occurs during frequency increment operations.
8    IncretmentError,
9    /// Error that occurs when parsing to a byte slice fails.
10    ParsingToByteError,
11    /// Error that occurs when parsing to a UTF-8 string fails.
12    ParsingToUTF8Error,
13    /// Wrapper for `sled::Error`.
14    SledError {
15        /// The underlying `sled` error.
16        error: sled::Error,
17    },
18    /// Error that occurs during a `sled` transaction.
19    SledTransactionError,
20    /// Error that occurs when parsing a byte slice to a u64 fails.
21    ParsingToU64ByteFailed,
22}
23
24impl Display for TransientError {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        match self {
27            TransientError::IncretmentError => writeln!(f, "Incretment has failed"),
28            TransientError::ParsingToByteError => writeln!(f, "Parsing to byte failed"),
29            TransientError::ParsingToUTF8Error => writeln!(f, "Parsing to utf8 failed"),
30            TransientError::SledError { error } => writeln!(f, "Sled failed {}", error),
31            TransientError::SledTransactionError => writeln!(f, "Sled Transaction failed"),
32            TransientError::ParsingToU64ByteFailed => {
33                writeln!(f, "Failed to parse a variable to a U64 byte [u8; 8]")
34            }
35        }
36    }
37}
38
39impl Error for TransientError {}