holochain_sqlite 0.6.1

Abstractions for persistence of Holochain state via SQLite
Documentation
//! All possible errors when working with SQLite databases

// missing_docs allowed here since the errors already have self-descriptive strings
#![allow(missing_docs)]

use holochain_serialized_bytes::SerializedBytesError;
use holochain_zome_types::prelude::*;
use std::path::PathBuf;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum DatabaseError {
    #[error("database directory does not exist at configured path: {0}")]
    DatabaseMissing(PathBuf),

    #[error("Error encoding to MsgPack: {0}")]
    MsgPackEncodeError(#[from] rmp_serde::encode::Error),

    #[error("Error decoding to MsgPack: {0}")]
    MsgPackDecodeError(#[from] rmp_serde::decode::Error),

    #[error("SerializedBytes error when attempting to interact with SQLite: {0}")]
    SerializedBytes(#[from] SerializedBytesError),

    #[error(transparent)]
    Other(#[from] anyhow::Error),

    #[error(transparent)]
    SqliteError(#[from] rusqlite::Error),

    #[error("Failure to remove directory")]
    DirectoryError(#[from] std::io::Error),

    #[error(transparent)]
    DbConnectionPoolError(#[from] r2d2::Error),

    #[error("transparent")]
    FailedToJoinBlocking(#[from] tokio::task::JoinError),

    #[error(transparent)]
    Timestamp(TimestampError),

    #[error(transparent)]
    GetRandom(getrandom::Error),

    #[error(transparent)]
    Timeout(tokio::time::error::Elapsed),
}

impl From<TimestampError> for DatabaseError {
    fn from(timestamp_error: TimestampError) -> Self {
        Self::Timestamp(timestamp_error)
    }
}

impl From<getrandom::Error> for DatabaseError {
    fn from(getrandom_error: getrandom::Error) -> Self {
        Self::GetRandom(getrandom_error)
    }
}

impl PartialEq for DatabaseError {
    fn eq(&self, other: &Self) -> bool {
        self.to_string() == other.to_string()
    }
}

pub type DatabaseResult<T> = Result<T, DatabaseError>;