Skip to main content

gitgraph_core/
error.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, GitLgError>;
6
7#[derive(Debug, Error)]
8pub enum GitLgError {
9    #[error("I/O failure while {operation}: {source}")]
10    Io {
11        operation: &'static str,
12        #[source]
13        source: std::io::Error,
14    },
15
16    #[error("git command failed: `{program}` {args:?}, exit_code={exit_code:?}, stderr={stderr}")]
17    GitCommandFailed {
18        program: String,
19        args: Vec<String>,
20        exit_code: Option<i32>,
21        stderr: String,
22        stdout: String,
23    },
24
25    #[error("invalid git repository: {0}")]
26    InvalidRepository(PathBuf),
27
28    #[error("parse error: {0}")]
29    Parse(String),
30
31    #[error("missing required placeholder value: {0}")]
32    MissingPlaceholder(String),
33
34    #[error("state error: {0}")]
35    State(String),
36}
37
38impl GitLgError {
39    pub fn io(operation: &'static str, source: std::io::Error) -> Self {
40        Self::Io { operation, source }
41    }
42}