1use git_bot_feedback::RestClientError;
2
3#[derive(Debug, thiserror::Error)]
4pub enum SuggestionError {
5 #[error("Failed to convert patch for '{file_name}' into bytes: {source}")]
6 PatchIntoBytesFailed {
7 file_name: String,
8 #[source]
9 source: git2::Error,
10 },
11 #[error("Failed to convert patch for file '{file_name}' into string: {source}")]
12 PatchIntoStringFailed {
13 file_name: String,
14 #[source]
15 source: std::string::FromUtf8Error,
16 },
17 #[error("Failed to get hunk {hunk_id} from patch for {file_name}: {source}")]
18 GetHunkFailed {
19 hunk_id: usize,
20 file_name: String,
21 #[source]
22 source: git2::Error,
23 },
24 #[error(
25 "Failed to get line {line_index} in a hunk {hunk_id} of patch for {file_name}: {source}"
26 )]
27 GetHunkLineFailed {
28 line_index: usize,
29 hunk_id: usize,
30 file_name: String,
31 #[source]
32 source: git2::Error,
33 },
34 #[error(
35 "Failed to convert line {line_index} buffer to string in hunk {hunk_id} of patch for {file_name}: {source}"
36 )]
37 HunkLineIntoStringFailed {
38 line_index: usize,
39 hunk_id: usize,
40 file_name: String,
41 #[source]
42 source: std::string::FromUtf8Error,
43 },
44}
45
46#[derive(Debug, thiserror::Error)]
47pub enum FileObjError {
48 #[error("Failed to read file contents")]
49 ReadFile(std::io::Error),
50 #[error("Failed to create patch for file {0:?}: {1}")]
51 MakePatchFailed(String, #[source] git2::Error),
52 #[error(transparent)]
53 SuggestionError(#[from] SuggestionError),
54}
55
56#[derive(Debug, thiserror::Error)]
57pub enum ClientError {
58 #[error(transparent)]
59 RestClientError(#[from] RestClientError),
60 #[error("Unsupported Git server or CI platform")]
61 GitServerUnsupported,
62 #[error("Mutex lock poisoned for a source file: {0}")]
63 MutexPoisoned(String),
64 #[error(transparent)]
65 FileObjError(#[from] FileObjError),
66}