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#[derive(Error, Debug)]
10pub enum Error {
11 #[error("`{0}`")]
13 Generic(String),
14
15 #[error("git: no head found")]
17 NoHead,
18
19 #[error("git: conflict during rebase")]
21 RebaseConflict,
22
23 #[error("git: remote url not found")]
25 UnknownRemote,
26
27 #[error("git: inconclusive remotes")]
29 NoDefaultRemoteFound,
30
31 #[error("git: work dir error")]
33 NoWorkDir,
34
35 #[error("git: uncommitted changes")]
37 UncommittedChanges,
38
39 #[error("git: can\u{2019}t run blame on a binary file")]
41 NoBlameOnBinaryFile,
42
43 #[error("binary file")]
45 BinaryFile,
46
47 #[error("io error:{0}")]
49 Io(#[from] std::io::Error),
50
51 #[error("git error:{0}")]
53 Git(#[from] git2::Error),
54
55 #[error("strip prefix error: {0}")]
57 StripPrefix(#[from] StripPrefixError),
58
59 #[error("utf8 error:{0}")]
61 Utf8Conversion(#[from] FromUtf8Error),
62
63 #[error("TryFromInt error:{0}")]
65 IntConversion(#[from] TryFromIntError),
66
67 #[error("EasyCast error:{0}")]
69 EasyCast(#[from] easy_cast::Error),
70
71 #[error("no parent of commit found")]
73 NoParent,
74
75 #[error("not on a branch")]
77 NoBranch,
78
79 #[error("rayon error: {0}")]
81 ThreadPool(#[from] rayon_core::ThreadPoolBuildError),
82
83 #[error("git hook error: {0}")]
85 Hooks(#[from] git2_hooks::HooksError),
86
87 #[error("sign builder error: {0}")]
89 SignBuilder(#[from] crate::sync::sign::SignBuilderError),
90
91 #[error("sign error: {0}")]
93 Sign(#[from] crate::sync::sign::SignError),
94
95 #[error(
97 "amend error: config commit.gpgsign=true detected.\ngpg signing is not supported for amending non-last commits"
98 )]
99 SignAmendNonLastCommit,
100
101 #[error(
103 "reword error: config commit.gpgsign=true detected.\ngpg signing is not supported for rewording non-last commits"
104 )]
105 SignRewordNonLastCommit,
106
107 #[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 #[error("serde json error:{0}")]
115 SerdeJson(#[from] SerdeJsonError),
116}
117
118pub 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}