epoch-db 0.2.9

An intelligent, persistent, and concurrent key-value store for Rust, designed to manage data with a lifecycle through frequency tracking and TTL.
Documentation
//! This module defines the custom error types used throughout the EpochDB
//! library.
use std::error::Error;
use std::fmt::Display;
use std::path::PathBuf;

/// The primary error enum for the EpochDB library.
/// Fun Fact: It's called TransientError because Transient is the old name of
/// the DB
#[derive(Debug)]
pub enum TransientError {
    /// Error that occurs during frequency increment operations.
    IncretmentError,
    /// Error that occurs when parsing to a byte slice fails.
    ParsingToByteError,
    /// Error that occurs when parsing to a UTF-8 string fails.
    ParsingToUTF8Error,
    /// Wrapper for `sled::Error`.
    SledError {
        /// The underlying `sled` error.
        error: sled::Error
    },
    /// Error that occurs during a `sled` transaction.
    SledTransactionError,
    /// Error that occurs when parsing a byte slice to a u64 fails.
    ParsingToU64ByteFailed,
    /// Error that occurs when any folder in the path doesnt exist.
    FolderNotFound { path: PathBuf },
    /// Wrapper for `zip::result::ZipError`.
    ZipError {
        /// The underlying `zip::result::ZipError`.
        error: zip::result::ZipError
    },
    /// Error that occurs when the file doesnt exist.
    FileNameDoesntExist,
    /// Error that occurs when the corresponding Metadata doesnt exist.
    MetadataNotFound,
    /// Error that occurs when the Metadata of the database itself doesnt exist.
    DBMetadataNotFound,
    /// Error that occurs when a Mutex is poisoned.
    PoisonedMutex,
    /// Error that occurs when parsing from a byte slice to any type.
    ParsingFromByteError,
    /// Wrapper for `std::io::Error`.
    IOError {
        /// The underlying `std::io::Error`
        error: std::io::Error
    }
}

impl Display for TransientError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            TransientError::IncretmentError => writeln!(f, "Incretment has failed"),
            TransientError::ParsingToByteError => writeln!(f, "Parsing to byte failed"),
            TransientError::ParsingToUTF8Error => writeln!(f, "Parsing to utf8 failed"),
            TransientError::SledError {
                error
            } => writeln!(f, "Sled failed {error}"),
            TransientError::SledTransactionError => writeln!(f, "Sled Transaction failed"),
            TransientError::ParsingToU64ByteFailed => {
                writeln!(f, "Failed to parse a variable to a U64 byte [u8; 8]")
            },
            TransientError::FolderNotFound {
                path
            } => {
                writeln!(f, "Folder is not found at the path: {path:#?}")
            },
            TransientError::ZipError {
                error
            } => writeln!(f, "Zip crate failed {error}"),
            TransientError::FileNameDoesntExist => writeln!(f, "File name doesnt exist"),
            TransientError::MetadataNotFound => writeln!(f, "Metadata is not found"),
            TransientError::DBMetadataNotFound => writeln!(f, "DB metadata is not found"),
            TransientError::PoisonedMutex => writeln!(f, "Mutex is poisoned"),
            TransientError::ParsingFromByteError => writeln!(f, "Partsing from byte failed"),
            TransientError::IOError {
                error
            } => writeln!(f, "std IO failed {error}")
        }
    }
}

impl Error for TransientError {}