Skip to main content

panproto_git/
error.rs

1//! Error types for git bridge operations.
2
3use miette::Diagnostic;
4
5/// Errors from git ↔ panproto-vcs translation.
6#[non_exhaustive]
7#[derive(Debug, thiserror::Error, Diagnostic)]
8pub enum GitBridgeError {
9    /// A git operation failed.
10    #[error("git error: {0}")]
11    Git(#[from] git2::Error),
12
13    /// A panproto-vcs operation failed.
14    #[error("vcs error: {0}")]
15    Vcs(#[from] panproto_vcs::VcsError),
16
17    /// A project assembly operation failed.
18    #[error("project error: {0}")]
19    Project(#[from] panproto_project::ProjectError),
20
21    /// A parse operation failed.
22    #[error("parse error: {0}")]
23    Parse(#[from] panproto_parse::ParseError),
24
25    /// The git repository has no commits.
26    #[error("repository has no commits")]
27    EmptyRepository,
28
29    /// A git object could not be read.
30    #[error("failed to read git object {oid}: {reason}")]
31    ObjectRead {
32        /// The git object ID.
33        oid: String,
34        /// The reason the read failed.
35        reason: String,
36    },
37
38    /// A file in the git tree could not be decoded as UTF-8.
39    #[error("file {path} is not valid UTF-8")]
40    NotUtf8 {
41        /// The file path.
42        path: String,
43    },
44
45    /// An on-disk blob cache failed to load or save.
46    ///
47    /// Distinct from a missing cache file, which is treated as an
48    /// empty map: this variant is emitted only for genuine corruption
49    /// or I/O failure. Callers with a `--reset-blob-cache` flag can
50    /// match on this and delete the file before retrying.
51    #[error("blob cache error: {0}")]
52    BlobCache(String),
53
54    /// A git tree entry name is not valid UTF-8.
55    ///
56    /// Panproto protocol detection and cross-file import resolution
57    /// both key on UTF-8 paths, so a non-UTF-8 tree entry is a
58    /// genuine error rather than something to be silently mapped to
59    /// `"(unnamed)"`.
60    #[error("git tree entry name is not valid UTF-8 under parent {parent:?}")]
61    NonUtf8TreeEntry {
62        /// Display of the parent path, using forward slashes.
63        parent: String,
64    },
65}