Skip to main content

contextgraph_core/
error.rs

1use crate::commit::CommitId;
2use thiserror::Error;
3
4/// All errors surfaced by contextgraph-core.
5///
6/// Every fallible operation in this crate returns `Result<_, GraphError>` on
7/// every path; there is no `unwrap`/`expect` outside tests.
8#[derive(Debug, Error)]
9pub enum GraphError {
10    #[error("parent commit not found: {0}")]
11    ParentNotFound(CommitId),
12
13    #[error("commit not found: {0}")]
14    CommitNotFound(CommitId),
15
16    #[error("branch not found: {0}")]
17    BranchNotFound(String),
18
19    #[error("branch already exists: {0}")]
20    BranchAlreadyExists(String),
21
22    #[error("merge parents must be two distinct, existing commits")]
23    InvalidMergeParents,
24
25    #[error("no common ancestor between {0} and {1}")]
26    NoCommonAncestor(CommitId, CommitId),
27
28    #[error("bisect range is invalid: {0} is not an ancestor of {1}")]
29    InvalidBisectRange(CommitId, CommitId),
30
31    #[error("invalid tag filter: {0}")]
32    InvalidFilter(String),
33
34    #[error("serialization error: {0}")]
35    Serialization(#[from] serde_json::Error),
36
37    #[error("storage error: {0}")]
38    Storage(String),
39
40    #[error("invalid commit id: {0}")]
41    InvalidCommitId(String),
42}
43
44pub type Result<T> = std::result::Result<T, GraphError>;