use std::io;
use std::path::PathBuf;
use crate::content_address::GraphHash;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("graph store I/O at {path}: {source}")]
Io {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("redb database error: {0}")]
Db(#[from] redb::DatabaseError),
#[error("redb transaction error: {0}")]
Transaction(#[from] redb::TransactionError),
#[error("redb table error: {0}")]
Table(#[from] redb::TableError),
#[error("redb storage error: {0}")]
Storage(#[from] redb::StorageError),
#[error("redb commit error: {0}")]
Commit(#[from] redb::CommitError),
#[error("graph not found: {hash}")]
NotFound { hash: GraphHash },
#[error("hash mismatch on blob {expected}: bytes hash to {actual}")]
HashMismatch {
expected: GraphHash,
actual: GraphHash,
},
#[error("rkyv validation failed for blob {hash}: {message}")]
Validation { hash: GraphHash, message: String },
#[error("invalid graph hash {input:?}: {reason}")]
BadHash { input: String, reason: &'static str },
}
impl Error {
pub fn io(path: impl Into<PathBuf>, source: io::Error) -> Self {
Self::Io {
path: path.into(),
source,
}
}
}