1use std::io;
9use std::path::PathBuf;
10
11use crate::content_address::GraphHash;
12
13pub type Result<T> = std::result::Result<T, Error>;
14
15#[derive(Debug, thiserror::Error)]
16pub enum Error {
17 #[error("graph store I/O at {path}: {source}")]
18 Io {
19 path: PathBuf,
20 #[source]
21 source: io::Error,
22 },
23
24 #[error("redb database error: {0}")]
25 Db(#[from] redb::DatabaseError),
26
27 #[error("redb transaction error: {0}")]
28 Transaction(#[from] redb::TransactionError),
29
30 #[error("redb table error: {0}")]
31 Table(#[from] redb::TableError),
32
33 #[error("redb storage error: {0}")]
34 Storage(#[from] redb::StorageError),
35
36 #[error("redb commit error: {0}")]
37 Commit(#[from] redb::CommitError),
38
39 #[error("graph not found: {hash}")]
41 NotFound { hash: GraphHash },
42
43 #[error("hash mismatch on blob {expected}: bytes hash to {actual}")]
47 HashMismatch {
48 expected: GraphHash,
49 actual: GraphHash,
50 },
51
52 #[error("rkyv validation failed for blob {hash}: {message}")]
56 Validation { hash: GraphHash, message: String },
57
58 #[error("invalid graph hash {input:?}: {reason}")]
61 BadHash { input: String, reason: &'static str },
62}
63
64impl Error {
65 pub fn io(path: impl Into<PathBuf>, source: io::Error) -> Self {
66 Self::Io {
67 path: path.into(),
68 source,
69 }
70 }
71}