Skip to main content

lattice_vcs/
error.rs

1use thiserror::Error;
2
3/// Error type for all `lattice-vcs` operations.
4#[derive(Error, Debug)]
5pub enum VcsError {
6    /// An error from the underlying `gix` library.
7    /// Boxed to avoid large-`Err` on the hot path.
8    #[error("git error: {0}")]
9    Git(Box<gix::discover::Error>),
10
11    /// A git object could not be resolved.
12    #[error("object not found: {0}")]
13    ObjectNotFound(String),
14
15    /// A reference could not be resolved.
16    #[error("reference not found: {0}")]
17    ReferenceNotFound(String),
18
19    /// Git command execution failed to start.
20    #[error("git command failed to start ({context}): {source}")]
21    GitCommand {
22        context: String,
23        #[source]
24        source: std::io::Error,
25    },
26
27    /// Git command exited with non-zero status.
28    #[error("git command failed: {stderr}")]
29    GitCommandFailed { stderr: String },
30
31    /// UTF-8 conversion failed for git output.
32    #[error("utf-8 conversion failed ({context}): {source}")]
33    Utf8 {
34        context: String,
35        #[source]
36        source: std::string::FromUtf8Error,
37    },
38
39    /// Operation attempted on a bare repository where a working tree
40    /// is required.
41    #[error("operation requires a working tree, but this is a bare repository: {0}")]
42    BareRepo(String),
43
44    /// Index (staging) operation failed.
45    #[error("index operation failed: {0}")]
46    Index(String),
47
48    /// Stash operation failed.
49    #[error("stash operation failed: {0}")]
50    Stash(String),
51
52    /// Remote management operation failed.
53    #[error("remote operation failed: {0}")]
54    Remote(String),
55
56    /// Bisect operation failed.
57    #[error("bisect operation failed: {0}")]
58    Bisect(String),
59
60    /// Submodule operation failed.
61    #[error("submodule operation failed: {0}")]
62    Submodule(String),
63
64    /// Notes operation failed (MG.37).
65    #[error("notes operation failed: {0}")]
66    Note(String),
67
68    /// A working-tree status entry could not be parsed.
69    #[error("status parse error: {0}")]
70    StatusParse(String),
71}
72
73impl From<gix::discover::Error> for VcsError {
74    fn from(e: gix::discover::Error) -> Self {
75        VcsError::Git(Box::new(e))
76    }
77}
78
79/// Convenience result type alias.
80pub type Result<T, E = VcsError> = std::result::Result<T, E>;