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