Skip to main content

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 context snapshot object.
62    #[error("Not a valid agent context snapshot object: {0}")]
63    InvalidContextSnapshotObject(String),
64
65    /// Malformed decision object.
66    #[error("Not a valid agent decision object: {0}")]
67    InvalidDecisionObject(String),
68
69    /// Malformed evidence object.
70    #[error("Not a valid agent evidence object: {0}")]
71    InvalidEvidenceObject(String),
72
73    /// Malformed patch set object.
74    #[error("Not a valid agent patch set object: {0}")]
75    InvalidPatchSetObject(String),
76
77    /// Malformed plan object.
78    #[error("Not a valid agent plan object: {0}")]
79    InvalidPlanObject(String),
80
81    /// Malformed provenance object.
82    #[error("Not a valid agent provenance object: {0}")]
83    InvalidProvenanceObject(String),
84
85    /// Malformed run object.
86    #[error("Not a valid agent run object: {0}")]
87    InvalidRunObject(String),
88
89    /// Malformed task object.
90    #[error("Not a valid agent task object: {0}")]
91    InvalidTaskObject(String),
92
93    /// Malformed intent object.
94    #[error("Not a valid agent intent object: {0}")]
95    InvalidIntentObject(String),
96
97    /// Malformed tool invocation object.
98    #[error("Not a valid agent tool invocation object: {0}")]
99    InvalidToolInvocationObject(String),
100
101    /// Malformed context frame object.
102    #[error("Not a valid agent context frame object: {0}")]
103    InvalidContextFrameObject(String),
104
105    /// Malformed or unsupported index (.idx) file.
106    #[error("The `{0}` is not a valid idx file.")]
107    InvalidIdxFile(String),
108
109    /// Malformed or unsupported pack file.
110    #[error("The `{0}` is not a valid pack file.")]
111    InvalidPackFile(String),
112
113    /// Invalid pack header magic or version.
114    #[error("The `{0}` is not a valid pack header.")]
115    InvalidPackHeader(String),
116
117    /// Malformed or unsupported git index file.
118    #[error("The `{0}` is not a valid index file.")]
119    InvalidIndexFile(String),
120
121    /// Invalid git index header.
122    #[error("The `{0}` is not a valid index header.")]
123    InvalidIndexHeader(String),
124
125    /// Invalid CLI or function argument.
126    #[error("Argument parse failed: {0}")]
127    InvalidArgument(String),
128
129    /// I/O error from underlying reader or writer.
130    #[error("IO Error: {0}")]
131    IOError(#[from] std::io::Error),
132
133    /// Invalid SHA1/SHA256 hash formatting or value.
134    #[error("The {0} is not a valid Hash value ")]
135    InvalidHashValue(String),
136
137    /// Delta object reconstruction error.
138    #[error("Delta Object Error Info:{0}")]
139    DeltaObjectError(String),
140
141    /// Object not fully populated for packing.
142    #[error("The object to be packed is incomplete ,{0}")]
143    UnCompletedPackObject(String),
144
145    /// Invalid decoded object info.
146    #[error("Error decode in the Object ,info:{0}")]
147    InvalidObjectInfo(String),
148
149    /// Hash not found in current file context.
150    #[error("Cannot find Hash value: {0} from current file")]
151    NotFoundHashValue(String),
152
153    /// Failed to encode object to bytes.
154    #[error("Can't encode the object which id [{0}] to bytes")]
155    EncodeObjectError(String),
156
157    /// Text encoding or UTF-8 conversion error.
158    #[error("UTF-8 conversion error: {0}")]
159    ConversionError(String),
160
161    /// Invalid path when locating parent tree.
162    #[error("Can't find parent tree by path: {0}")]
163    InvalidPathError(String),
164
165    /// Failed to encode pack entries.
166    #[error("Can't encode entries to pack: {0}")]
167    PackEncodeError(String),
168
169    /// Object missing from caches or storage.
170    #[error("Can't find specific object: {0}")]
171    ObjectNotFound(String),
172
173    /// Repository not found.
174    #[error("Repository not found")]
175    RepoNotFound,
176
177    /// Unauthorized access.
178    #[error("UnAuthorized: {0}")]
179    UnAuthorized(String),
180
181    /// Network communication error.
182    #[error("Network Error: {0}")]
183    NetworkError(String),
184
185    /// Generic custom error for miscellaneous failures.
186    #[error("{0}")]
187    CustomError(String),
188}