fluidattacks_core_git/
errors.rs1use std::io;
2use std::path::PathBuf;
3use std::process::ExitStatus;
4use std::time::Duration;
5
6#[derive(Debug, thiserror::Error)]
8#[error("{action} {}: {source}", path.display())]
9pub struct FileError {
10 pub action: &'static str,
11 pub path: PathBuf,
12 #[source]
13 pub source: io::Error,
14}
15
16#[derive(Debug, thiserror::Error)]
18pub enum PruneError {
19 #[error(transparent)]
20 File(#[from] FileError),
21 #[error(transparent)]
23 Git(#[from] GitCallError),
24}
25
26#[derive(Debug, thiserror::Error)]
28pub enum ResetError {
29 #[error(transparent)]
31 Git(#[from] GitCallError),
32 #[error(transparent)]
33 Symlinks(#[from] FileError),
34}
35
36#[derive(Debug, PartialEq, Eq, thiserror::Error)]
38pub enum HttpsAccessError {
39 #[error("Invalid credentials: a line break or a nul byte")]
41 CredentialLineBreak,
42 #[error("expected an http or https url")]
43 NotHttp,
44 #[error("Invalid url: its host or port could not be parsed")]
46 Unparsable,
47 #[error("expected an https credential")]
48 NotHttpsCredential,
49}
50
51#[derive(Debug, thiserror::Error)]
53pub enum CloneError {
54 #[error(transparent)]
55 Access(#[from] HttpsAccessError),
56 #[error(transparent)]
57 Git(#[from] GitCallError),
58 #[error(transparent)]
60 Info(#[from] FileError),
61 #[error(transparent)]
62 SshKey(#[from] SshKeyError),
63 #[error(transparent)]
64 Sts(#[from] StsError),
65}
66
67#[derive(Debug, thiserror::Error)]
69pub enum SshKeyError {
70 #[error("the SSH key is not base64: {0}")]
71 Decode(#[from] base64::DecodeError),
72 #[error("the SSH key could not be written: {0}")]
73 File(#[source] io::Error),
74 #[error("the SSH key path cannot be quoted for the shell: {0}")]
75 Path(#[from] shlex::QuoteError),
76}
77
78#[derive(Debug, thiserror::Error)]
80pub enum LsRemoteError {
81 #[error(transparent)]
82 SshKey(#[from] SshKeyError),
83 #[error(transparent)]
84 Git(#[from] GitCallError),
85}
86
87#[derive(Debug, thiserror::Error)]
89pub enum StsError {
90 #[error("STS refused the role {arn}: {code}: {message}")]
92 Refused {
93 arn: String,
94 code: String,
95 message: String,
96 },
97 #[error("STS could not be asked for the role {arn}: {reason}")]
99 Unreachable { arn: String, reason: String },
100 #[error("STS answered the role {arn} without credentials")]
101 NoCredentials { arn: String },
102}
103
104#[derive(Debug, thiserror::Error)]
105pub enum GitCallError {
106 #[error("git {command} could not start: {source}")]
107 NotStarted {
108 command: &'static str,
109 source: io::Error,
110 },
111 #[error("git {command} did not finish within {after:?}")]
112 TimedOut {
113 command: &'static str,
114 after: Duration,
115 },
116 #[error("git {command} exited with {status}: {stderr}")]
118 Refused {
119 command: &'static str,
120 status: ExitStatus,
121 stderr: String,
122 },
123 #[error("git {command} got an argument with an embedded null byte")]
125 NullByte { command: &'static str },
126 #[error("git {command} printed something unreadable: {reason}")]
127 Malformed {
128 command: &'static str,
129 reason: String,
130 },
131}
132
133#[derive(Debug, thiserror::Error)]
135pub enum DownloadError {
136 #[error("writing the archive: {0}")]
139 Write(#[source] io::Error),
140 #[error(transparent)]
141 Fetch(#[from] FetchError),
142 #[error(transparent)]
143 Extract(#[from] ExtractError),
144 #[error(transparent)]
146 Reset(#[from] GitCallError),
147 #[error("pruning the working tree: {0}")]
148 Prune(#[from] PruneError),
149 #[error("placing the repository: {0}")]
152 Place(#[source] io::Error),
153}
154
155#[derive(Debug, thiserror::Error)]
157pub enum FetchError {
158 #[error("invalid url {url}: {reason}")]
159 InvalidUrl { url: String, reason: String },
160 #[error("not an http url: {0}")]
161 NonHttpUrl(String),
162 #[error("could not connect: {0}")]
164 Connect(#[source] reqwest::Error),
165 #[error("connecting timed out: {0}")]
166 ConnectTimeout(#[source] reqwest::Error),
167 #[error("no response in time: {0}")]
169 Timeout(#[source] reqwest::Error),
170 #[error("the server disconnected: {0}")]
172 Disconnected(#[source] reqwest::Error),
173 #[error("the socket failed: {source}")]
176 Socket {
177 reset: bool,
178 errno: Option<i32>,
179 source: reqwest::Error,
180 },
181 #[error("malformed response: {0}")]
182 Malformed(#[source] reqwest::Error),
183 #[error("the server answered {0}")]
184 Status(reqwest::StatusCode),
185 #[error("the body was cut: {0}")]
187 BodyCut(#[source] reqwest::Error),
188 #[error("the body did not arrive in time: {0}")]
190 BodyTimeout(#[source] reqwest::Error),
191 #[error("the request failed: {0}")]
192 Other(#[source] reqwest::Error),
193}
194
195#[derive(Debug, thiserror::Error)]
197pub enum ExtractError {
198 #[error("corrupt archive: {0}")]
201 Corrupt(#[source] io::Error),
202 #[error("truncated archive: {0}")]
204 Truncated(#[source] io::Error),
205 #[error("the archive holds no repository: {0}")]
207 NoRepository(String),
208 #[error("extracting the archive: {0}")]
209 Io(#[source] io::Error),
210}