gnostr_asyncgit/
error.rs

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