Skip to main content

git_meta_lib/
error.rs

1/// Typed error enum for all gmeta operations.
2///
3/// Covers database, git, parsing, and domain-specific errors.
4/// External consumers can match on variants to handle specific failure modes.
5#[derive(Debug, thiserror::Error)]
6#[non_exhaustive]
7pub enum Error {
8    /// SQLite operation failed.
9    #[error(transparent)]
10    Sqlite(#[from] rusqlite::Error),
11
12    /// Git operation failed.
13    #[error("git error: {0}")]
14    Git(#[from] Box<dyn std::error::Error + Send + Sync>),
15
16    /// JSON serialization or deserialization failed.
17    #[error(transparent)]
18    Json(#[from] serde_json::Error),
19
20    /// Unknown target type string (e.g. not "commit", "branch", etc.).
21    #[error("unknown target type: {0}")]
22    UnknownTargetType(String),
23
24    /// Target string could not be parsed (wrong format, too short, etc.).
25    #[error("{0}")]
26    InvalidTarget(String),
27
28    /// Key validation failed (empty, reserved segment, invalid characters).
29    #[error("{0}")]
30    InvalidKey(String),
31
32    /// Unknown value type string (not "string", "list", or "set").
33    #[error("unknown value type: {0}")]
34    UnknownValueType(String),
35
36    /// Metadata key does not exist for the given target.
37    #[error("key '{key}' not found")]
38    KeyNotFound {
39        /// The key that was not found.
40        key: String,
41    },
42
43    /// Key exists but has a different value type than expected.
44    #[error("key '{key}' is not a {expected}")]
45    TypeMismatch {
46        /// The key whose type didn't match.
47        key: String,
48        /// The type that was expected (e.g. "list", "set").
49        expected: String,
50    },
51
52    /// A specific value was not found in a list or set.
53    #[error("value not found: {0}")]
54    ValueNotFound(String),
55
56    /// Index is out of range for a list operation.
57    #[error("index {index} out of range ({size} entries)")]
58    IndexOutOfRange {
59        /// The requested index.
60        index: usize,
61        /// The actual size of the collection.
62        size: usize,
63    },
64
65    /// A value was malformed or invalid (JSON encoding, list entry format, etc.).
66    #[error("{0}")]
67    InvalidValue(String),
68
69    /// No git repository found in the current directory or any parent.
70    #[error("not a git repository (or any parent up to mount point)")]
71    NotARepository,
72
73    /// Could not resolve a partial commit SHA or ref.
74    #[error("could not resolve: {0}")]
75    ResolveError(String),
76
77    /// A git subprocess command failed.
78    #[error("git command failed: {0}")]
79    GitCommand(String),
80
81    /// No metadata remotes are configured.
82    #[error("no metadata remotes configured")]
83    NoRemotes,
84
85    /// The specified remote is not a metadata remote.
86    #[error("'{0}' is not a metadata remote")]
87    RemoteNotFound(String),
88
89    /// A filter rule string could not be parsed.
90    #[error("invalid filter rule: {0}")]
91    InvalidFilterRule(String),
92
93    /// A tree path could not be parsed or is structurally invalid.
94    #[error("invalid tree path: {0}")]
95    InvalidTreePath(String),
96
97    /// Catch-all for errors that don't fit other variants.
98    #[error("{0}")]
99    Other(String),
100}
101
102/// A `Result` type alias using [`Error`] as the default error type.
103pub type Result<T, E = Error> = std::result::Result<T, E>;