Skip to main content

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 bare repository was found but access is forbidden by safe.bareRepository.
18    #[error("cannot use bare repository '{0}' (safe.bareRepository is 'explicit')")]
19    ForbiddenBareRepository(String),
20
21    /// The repository is owned by a different user (safe.directory).
22    #[error("detected dubious ownership in repository at '{0}'")]
23    DubiousOwnership(String),
24
25    /// Repository format version is not supported by this implementation.
26    #[error("unsupported repository format version '{0}'")]
27    UnsupportedRepositoryFormatVersion(u32),
28
29    /// Repository declares an unsupported extension.
30    #[error("unknown repository extension '{0}'")]
31    UnsupportedRepositoryExtension(String),
32
33    /// A supplied object ID string was not valid hex or the wrong length.
34    #[error("invalid object id '{0}'")]
35    InvalidObjectId(String),
36
37    /// The requested object does not exist in the object store.
38    #[error("object not found: {0}")]
39    ObjectNotFound(String),
40
41    /// An object's stored data is corrupt or malformed.
42    #[error("corrupt object: {0}")]
43    CorruptObject(String),
44
45    /// An unsupported or unknown object type was encountered.
46    #[error("unknown object type '{0}'")]
47    UnknownObjectType(String),
48
49    /// Loose object header type field exceeds Git's 32-byte limit.
50    #[error("header for {oid} too long, exceeds 32 bytes")]
51    ObjectHeaderTooLong { oid: String },
52
53    /// An I/O error from the underlying filesystem.
54    #[error("I/O error: {0}")]
55    Io(#[from] std::io::Error),
56
57    /// A zlib compression or decompression failure.
58    #[error("zlib error: {0}")]
59    Zlib(String),
60
61    /// The index file is missing, truncated, or has a bad header.
62    #[error("index error: {0}")]
63    IndexError(String),
64
65    /// A reference name or value is invalid.
66    #[error("invalid ref: {0}")]
67    InvalidRef(String),
68
69    /// A general path-related error (invalid UTF-8, out-of-bounds, etc.).
70    #[error("path error: {0}")]
71    PathError(String),
72
73    /// A configuration file parsing or access error.
74    #[error("config error: {0}")]
75    ConfigError(String),
76}
77
78/// Convenience alias for `Result<T, Error>`.
79pub type Result<T> = std::result::Result<T, Error>;