git_internal/
errors.rs

1//! Error types for the Git-Internal crate.
2//!
3//! This module defines a unified error enumeration used across object parsing,
4//! pack encoding/decoding, index handling, caching, and streaming. It integrates
5//! with `thiserror` to provide rich `Display` implementations and error source
6//! chaining where applicable.
7//!
8//! Notes:
9//! - Each variant carries contextual details via its message payload.
10//! - Variants cover parse/validation, I/O, encoding/decoding, network/auth,
11//!   and custom errors.
12
13use thiserror::Error;
14
15#[derive(Error, Debug)]
16/// Unified error enumeration for the Git-Internal library.
17///
18/// - Used across object parsing, pack encode/decode, index, caching and streams.
19/// - Implements `std::error::Error` via `thiserror`.
20pub enum GitError {
21    /// Invalid or unsupported git object type name.
22    #[error("The `{0}` is not a valid git object type.")]
23    InvalidObjectType(String),
24
25    /// Malformed or unsupported blob object encoding.
26    #[error("The `{0}` is not a valid git blob object.")]
27    InvalidBlobObject(String),
28
29    /// Malformed tree object.
30    #[error("Not a valid git tree object.")]
31    InvalidTreeObject,
32
33    /// Invalid tree entry (mode/name/hash).
34    #[error("The `{0}` is not a valid git tree item.")]
35    InvalidTreeItem(String),
36
37    /// Tree contains no entries.
38    #[error("`{0}`.")]
39    EmptyTreeItems(String),
40
41    /// Invalid commit signature type.
42    #[error("The `{0}` is not a valid git commit signature.")]
43    InvalidSignatureType(String),
44
45    /// Malformed commit object.
46    #[error("Not a valid git commit object.")]
47    InvalidCommitObject,
48
49    /// Commit parse or validation failed.
50    #[error("Invalid Commit: {0}")]
51    InvalidCommit(String),
52
53    /// Malformed tag object.
54    #[error("Not a valid git tag object: {0}")]
55    InvalidTagObject(String),
56
57    /// Malformed note object.
58    #[error("Not a valid git note object: {0}")]
59    InvalidNoteObject(String),
60
61    /// Malformed or unsupported index (.idx) file.
62    #[error("The `{0}` is not a valid idx file.")]
63    InvalidIdxFile(String),
64
65    /// Malformed or unsupported pack file.
66    #[error("The `{0}` is not a valid pack file.")]
67    InvalidPackFile(String),
68
69    /// Invalid pack header magic or version.
70    #[error("The `{0}` is not a valid pack header.")]
71    InvalidPackHeader(String),
72
73    /// Malformed or unsupported git index file.
74    #[error("The `{0}` is not a valid index file.")]
75    InvalidIndexFile(String),
76
77    /// Invalid git index header.
78    #[error("The `{0}` is not a valid index header.")]
79    InvalidIndexHeader(String),
80
81    /// Invalid CLI or function argument.
82    #[error("Argument parse failed: {0}")]
83    InvalidArgument(String),
84
85    /// I/O error from underlying reader or writer.
86    #[error("IO Error: {0}")]
87    IOError(#[from] std::io::Error),
88
89    /// Invalid SHA1 hash formatting or value.
90    #[error("The {0} is not a valid Hash value ")]
91    InvalidHashValue(String),
92
93    /// Delta object reconstruction error.
94    #[error("Delta Object Error Info:{0}")]
95    DeltaObjectError(String),
96
97    /// Object not fully populated for packing.
98    #[error("The object to be packed is incomplete ,{0}")]
99    UnCompletedPackObject(String),
100
101    /// Invalid decoded object info.
102    #[error("Error decode in the Object ,info:{0}")]
103    InvalidObjectInfo(String),
104
105    /// Hash not found in current file context.
106    #[error("Cannot find Hash value: {0} from current file")]
107    NotFoundHashValue(String),
108
109    /// Failed to encode object to bytes.
110    #[error("Can't encode the object which id [{0}] to bytes")]
111    EncodeObjectError(String),
112
113    /// Text encoding or UTF-8 conversion error.
114    #[error("UTF-8 conversion error: {0}")]
115    ConversionError(String),
116
117    /// Invalid path when locating parent tree.
118    #[error("Can't find parent tree by path: {0}")]
119    InvalidPathError(String),
120
121    /// Failed to encode pack entries.
122    #[error("Can't encode entries to pack: {0}")]
123    PackEncodeError(String),
124
125    /// Object missing from caches or storage.
126    #[error("Can't find specific object: {0}")]
127    ObjectNotFound(String),
128
129    /// Repository not found.
130    #[error("Repository not found")]
131    RepoNotFound,
132
133    /// Unauthorized access.
134    #[error("UnAuthorized: {0}")]
135    UnAuthorized(String),
136
137    /// Network communication error.
138    #[error("Network Error: {0}")]
139    NetworkError(String),
140
141    /// Generic custom error for miscellaneous failures.
142    #[error("{0}")]
143    CustomError(String),
144}