gnostr_asyncgit/
error.rs

1#![allow(renamed_and_removed_lints, clippy::unknown_clippy_lints)]
2
3use std::{num::TryFromIntError, path::StripPrefixError, string::FromUtf8Error};
4
5use thiserror::Error;
6
7///
8#[derive(Error, Debug)]
9pub enum Error {
10    ///
11    #[error("`{0}`")]
12    Generic(String),
13
14    ///
15    #[error("git: no head found")]
16    NoHead,
17
18    ///
19    #[error("git: conflict during rebase")]
20    RebaseConflict,
21
22    ///
23    #[error("git: remote url not found")]
24    UnknownRemote,
25
26    ///
27    #[error("git: inconclusive remotes")]
28    NoDefaultRemoteFound,
29
30    ///
31    #[error("git: work dir error")]
32    NoWorkDir,
33
34    ///
35    #[error("git: uncommitted changes")]
36    UncommittedChanges,
37
38    ///
39    #[error("git: can\u{2019}t run blame on a binary file")]
40    NoBlameOnBinaryFile,
41
42    ///
43    #[error("binary file")]
44    BinaryFile,
45
46    ///
47    #[error("io error:{0}")]
48    Io(#[from] std::io::Error),
49
50    ///
51    #[error("git error:{0}")]
52    Git(#[from] git2::Error),
53
54    ///
55    #[error("strip prefix error: {0}")]
56    StripPrefix(#[from] StripPrefixError),
57
58    ///
59    #[error("utf8 error:{0}")]
60    Utf8Conversion(#[from] FromUtf8Error),
61
62    ///
63    #[error("TryFromInt error:{0}")]
64    IntConversion(#[from] TryFromIntError),
65
66    ///
67    #[error("EasyCast error:{0}")]
68    EasyCast(#[from] easy_cast::Error),
69
70    ///
71    #[error("no parent of commit found")]
72    NoParent,
73
74    ///
75    #[error("not on a branch")]
76    NoBranch,
77
78    ///
79    #[error("rayon error: {0}")]
80    ThreadPool(#[from] rayon_core::ThreadPoolBuildError),
81
82    ///
83    #[error("git hook error: {0}")]
84    Hooks(#[from] git2_hooks::HooksError),
85
86    ///
87    #[error("sign builder error: {0}")]
88    SignBuilder(#[from] crate::sync::sign::SignBuilderError),
89
90    ///
91    #[error("sign error: {0}")]
92    Sign(#[from] crate::sync::sign::SignError),
93
94    ///
95    #[error(
96		"amend error: config commit.gpgsign=true detected.\ngpg signing is not supported for amending non-last commits"
97	)]
98    SignAmendNonLastCommit,
99
100    ///
101    #[error(
102		"reword error: config commit.gpgsign=true detected.\ngpg signing is not supported for rewording non-last commits"
103	)]
104    SignRewordNonLastCommit,
105
106    ///
107    #[error(
108		"reword error: config commit.gpgsign=true detected.\ngpg signing is not supported for rewording commits with staged changes\ntry unstaging or stashing your changes"
109	)]
110    SignRewordLastCommitStaged,
111}
112
113///
114pub type Result<T> = std::result::Result<T, Error>;
115
116impl<T> From<std::sync::PoisonError<T>> for Error {
117    fn from(error: std::sync::PoisonError<T>) -> Self {
118        Self::Generic(format!("poison error: {error}"))
119    }
120}
121
122impl<T> From<crossbeam_channel::SendError<T>> for Error {
123    fn from(error: crossbeam_channel::SendError<T>) -> Self {
124        Self::Generic(format!("send error: {error}"))
125    }
126}