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