Skip to main content

si_git_commit/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, SiError>;
4
5#[derive(Error, Debug)]
6pub enum SiError {
7    #[error("config error: {0}")]
8    Config(String),
9
10    #[error("git error: {0}")]
11    Git(String),
12
13    #[error("{provider} API error: {message}")]
14    Api { provider: String, message: String },
15
16    #[error("no staged changes found. Stage files first (e.g. `ghsi stage` or `git add`)")]
17    NoStagedChanges,
18
19    #[error("no changes found to commit. Make sure you have modified files in your repository")]
20    NoChanges,
21
22    #[error("not inside a git repository")]
23    NotARepo,
24
25    #[error("IO error: {0}")]
26    Io(#[from] std::io::Error),
27
28    #[error("failed to parse config: {0}")]
29    TomlParse(#[from] toml::de::Error),
30
31    #[error("failed to serialize config: {0}")]
32    TomlSerialize(#[from] toml::ser::Error),
33
34    #[error("request failed: {0}")]
35    Http(#[from] reqwest::Error),
36
37    #[error("{0}")]
38    Other(String),
39}
40
41impl From<anyhow::Error> for SiError {
42    fn from(err: anyhow::Error) -> Self {
43        SiError::Other(err.to_string())
44    }
45}