use thiserror::Error;
#[non_exhaustive]
#[derive(Error, Debug)]
pub enum VsdbError {
#[error("branch not found: {branch_id}")]
BranchNotFound {
branch_id: u64,
},
#[error("commit not found: {commit_id}")]
CommitNotFound {
commit_id: u64,
},
#[error("branch already exists: {name}")]
BranchAlreadyExists {
name: String,
},
#[error("cannot delete the main branch")]
CannotDeleteMainBranch,
#[error("branch {branch_id} has uncommitted changes")]
UncommittedChanges {
branch_id: u64,
},
#[error("encoding error: {0}")]
Encoding(#[from] postcard::Error),
#[error("storage error: {0}")]
Io(#[from] std::io::Error),
#[error("trie error: {detail}")]
Trie {
detail: String,
},
#[error("{detail}")]
Other {
detail: String,
},
}
pub type Result<T> = std::result::Result<T, VsdbError>;
impl From<Box<dyn ruc::err::RucError>> for VsdbError {
fn from(e: Box<dyn ruc::err::RucError>) -> Self {
Self::Other {
detail: e.stringify_chain(None),
}
}
}