grit_lib/error.rs
1//! Shared error types for the Gust library.
2//!
3//! Library code uses [`Error`] (a `thiserror` enum) so callers can match on
4//! specific failure modes. The binary wraps these with `anyhow` for human-
5//! readable top-level reporting.
6
7use thiserror::Error;
8
9/// The top-level error type for all Gust library operations.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum Error {
13 /// A repository could not be found or is structurally invalid.
14 #[error("not a git repository (or any of the parent directories): {0}")]
15 NotARepository(String),
16
17 /// A supplied object ID string was not valid hex or the wrong length.
18 #[error("invalid object id '{0}'")]
19 InvalidObjectId(String),
20
21 /// The requested object does not exist in the object store.
22 #[error("object not found: {0}")]
23 ObjectNotFound(String),
24
25 /// An object's stored data is corrupt or malformed.
26 #[error("corrupt object: {0}")]
27 CorruptObject(String),
28
29 /// An unsupported or unknown object type was encountered.
30 #[error("unknown object type '{0}'")]
31 UnknownObjectType(String),
32
33 /// An I/O error from the underlying filesystem.
34 #[error("I/O error: {0}")]
35 Io(#[from] std::io::Error),
36
37 /// A zlib compression or decompression failure.
38 #[error("zlib error: {0}")]
39 Zlib(String),
40
41 /// The index file is missing, truncated, or has a bad header.
42 #[error("index error: {0}")]
43 IndexError(String),
44
45 /// A reference name or value is invalid.
46 #[error("invalid ref: {0}")]
47 InvalidRef(String),
48
49 /// A general path-related error (invalid UTF-8, out-of-bounds, etc.).
50 #[error("path error: {0}")]
51 PathError(String),
52
53 /// A configuration file parsing or access error.
54 #[error("config error: {0}")]
55 ConfigError(String),
56}
57
58/// Convenience alias for `Result<T, Error>`.
59pub type Result<T> = std::result::Result<T, Error>;