Skip to main content

grex_core/git/
error.rs

1//! Error taxonomy for the [`crate::git`] backend.
2//!
3//! Errors carry `String` detail fields rather than boxing underlying `gix`
4//! error types. Keeping the public API free of leaky backend types means the
5//! trait surface stays stable across backend swaps and `#[non_exhaustive]`
6//! can be safely extended in future slices (e.g. auth, shallow, submodules).
7
8use std::path::PathBuf;
9
10use thiserror::Error;
11
12/// Errors produced by any [`crate::git::GitBackend`] implementation.
13///
14/// The enum is `#[non_exhaustive]` so future slices (credentials, submodules,
15/// partial fetch) can add variants without a breaking change.
16#[non_exhaustive]
17#[derive(Debug, Error)]
18pub enum GitError {
19    /// Clone was asked to populate a destination that already contains files.
20    #[error("destination `{0}` is not empty")]
21    DestinationNotEmpty(PathBuf),
22
23    /// Operation was asked to act on a path that does not hold a git repo.
24    #[error("path `{0}` is not a git repository")]
25    NotARepository(PathBuf),
26
27    /// A ref (branch, tag, or SHA) could not be resolved in the repository.
28    #[error("ref `{0}` not found in repository")]
29    RefNotFound(String),
30
31    /// Checkout refused because the working tree has uncommitted changes.
32    #[error("working tree has uncommitted changes at `{0}`")]
33    DirtyWorkingTree(PathBuf),
34
35    /// Clone failed at the backend layer. `detail` carries the backend
36    /// message verbatim for operator diagnosis.
37    #[error("clone from `{url}` failed: {detail}")]
38    CloneFailed {
39        /// Remote URL that was being cloned.
40        url: String,
41        /// Backend-provided failure detail.
42        detail: String,
43    },
44
45    /// Fetch failed at the backend layer.
46    #[error("fetch failed at `{0}`: {1}")]
47    FetchFailed(PathBuf, String),
48
49    /// Checkout of a resolved ref failed to apply to the working tree.
50    #[error("checkout of `{ref}` failed: {detail}")]
51    CheckoutFailed {
52        /// Ref name (branch, tag, or SHA) that was being checked out.
53        r#ref: String,
54        /// Backend-provided failure detail.
55        detail: String,
56    },
57
58    /// Catch-all for unexpected backend errors. Carries the detail string so
59    /// the caller can log or surface it without losing information.
60    #[error("gix internal error: {0}")]
61    Internal(String),
62}