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#[derive(Error, Debug)]
9pub enum Error {
10 #[error("`{0}`")]
12 Generic(String),
13
14 #[error("git: no head found")]
16 NoHead,
17
18 #[error("git: conflict during rebase")]
20 RebaseConflict,
21
22 #[error("git: remote url not found")]
24 UnknownRemote,
25
26 #[error("git: inconclusive remotes")]
28 NoDefaultRemoteFound,
29
30 #[error("git: work dir error")]
32 NoWorkDir,
33
34 #[error("git: uncommitted changes")]
36 UncommittedChanges,
37
38 #[error("git: can\u{2019}t run blame on a binary file")]
40 NoBlameOnBinaryFile,
41
42 #[error("binary file")]
44 BinaryFile,
45
46 #[error("io error:{0}")]
48 Io(#[from] std::io::Error),
49
50 #[error("git error:{0}")]
52 Git(#[from] git2::Error),
53
54 #[error("strip prefix error: {0}")]
56 StripPrefix(#[from] StripPrefixError),
57
58 #[error("utf8 error:{0}")]
60 Utf8Conversion(#[from] FromUtf8Error),
61
62 #[error("TryFromInt error:{0}")]
64 IntConversion(#[from] TryFromIntError),
65
66 #[error("EasyCast error:{0}")]
68 EasyCast(#[from] easy_cast::Error),
69
70 #[error("no parent of commit found")]
72 NoParent,
73
74 #[error("not on a branch")]
76 NoBranch,
77
78 #[error("rayon error: {0}")]
80 ThreadPool(#[from] rayon_core::ThreadPoolBuildError),
81
82 #[error("git hook error: {0}")]
84 Hooks(#[from] git2_hooks::HooksError),
85
86 #[error("sign builder error: {0}")]
88 SignBuilder(#[from] crate::sync::sign::SignBuilderError),
89
90 #[error("sign error: {0}")]
92 Sign(#[from] crate::sync::sign::SignError),
93
94 #[error(
96 "amend error: config commit.gpgsign=true detected.\ngpg signing is not supported for amending non-last commits"
97 )]
98 SignAmendNonLastCommit,
99
100 #[error(
102 "reword error: config commit.gpgsign=true detected.\ngpg signing is not supported for rewording non-last commits"
103 )]
104 SignRewordNonLastCommit,
105
106 #[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
113pub 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}