1use 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 SshHostError {
90 #[error("Invalid ssh url: expected user@host:path or ssh://user@host[:port]/path")]
92 Malformed,
93 #[error("Could not resolve the hostname {host}: {source}")]
94 Unresolved {
95 host: String,
96 #[source]
97 source: io::Error,
98 },
99 #[error("No IP addresses resolved for hostname: {host}")]
100 NoAddresses { host: String },
101 #[error("SSH host validation failed for {host}: {reason}")]
102 Local {
103 host: String,
104 reason: crate::local_address::LocalAddress,
105 },
106}
107
108#[derive(Debug, thiserror::Error)]
110pub enum StsError {
111 #[error("STS refused the role {arn}: {code}: {message}")]
113 Refused {
114 arn: String,
115 code: String,
116 message: String,
117 },
118 #[error("STS took too long to connect for the role {arn}: {reason}")]
119 ConnectTimeout { arn: String, reason: String },
120 #[error("STS took too long to answer the role {arn}: {reason}")]
122 ReadTimeout { arn: String, reason: String },
123 #[error("STS closed the connection for the role {arn}: {reason}")]
125 ConnectionClosed { arn: String, reason: String },
126 #[error("STS could not be connected to for the role {arn}: {reason}")]
128 NoConnection { arn: String, reason: String },
129 #[error("STS could not be asked for the role {arn}: {reason}")]
131 Unreachable { arn: String, reason: String },
132 #[error("STS answered the role {arn} without credentials")]
133 NoCredentials { arn: String },
134}
135
136#[derive(Debug, thiserror::Error)]
138pub enum CodecommitLsRemoteError {
139 #[error(transparent)]
140 Sts(#[from] StsError),
141 #[error(transparent)]
142 Git(#[from] GitCallError),
143}
144
145#[derive(Debug, thiserror::Error)]
146pub enum GitCallError {
147 #[error("git {command} could not start: {source}")]
148 NotStarted {
149 command: &'static str,
150 source: io::Error,
151 },
152 #[error("git {command} did not finish within {after:?}")]
153 TimedOut {
154 command: &'static str,
155 after: Duration,
156 },
157 #[error("git {command} exited with {status}: {stderr}")]
159 Refused {
160 command: &'static str,
161 status: ExitStatus,
162 stderr: String,
163 },
164 #[error("git {command} got an argument with an embedded null byte")]
166 NullByte { command: &'static str },
167 #[error("git {command} printed something unreadable: {reason}")]
168 Malformed {
169 command: &'static str,
170 reason: String,
171 },
172}
173
174#[derive(Debug, thiserror::Error)]
176pub enum DownloadError {
177 #[error("writing the archive: {0}")]
180 Write(#[source] io::Error),
181 #[error(transparent)]
182 Fetch(#[from] FetchError),
183 #[error(transparent)]
184 Extract(#[from] ExtractError),
185 #[error(transparent)]
187 Reset(#[from] GitCallError),
188 #[error("pruning the working tree: {0}")]
189 Prune(#[from] PruneError),
190 #[error("placing the repository: {0}")]
193 Place(#[source] io::Error),
194}
195
196#[derive(Debug, thiserror::Error)]
198pub enum FetchError {
199 #[error("invalid url {url}: {reason}")]
200 InvalidUrl { url: String, reason: String },
201 #[error("not an http url: {0}")]
202 NonHttpUrl(String),
203 #[error("could not connect: {0}")]
205 Connect(#[source] reqwest::Error),
206 #[error("connecting timed out: {0}")]
207 ConnectTimeout(#[source] reqwest::Error),
208 #[error("no response in time: {0}")]
210 Timeout(#[source] reqwest::Error),
211 #[error("the server disconnected: {0}")]
213 Disconnected(#[source] reqwest::Error),
214 #[error("the socket failed: {source}")]
217 Socket {
218 reset: bool,
219 errno: Option<i32>,
220 source: reqwest::Error,
221 },
222 #[error("malformed response: {0}")]
223 Malformed(#[source] reqwest::Error),
224 #[error("the server answered {0}")]
225 Status(reqwest::StatusCode),
226 #[error("the body was cut: {0}")]
228 BodyCut(#[source] reqwest::Error),
229 #[error("the body did not arrive in time: {0}")]
231 BodyTimeout(#[source] reqwest::Error),
232 #[error("the request failed: {0}")]
233 Other(#[source] reqwest::Error),
234}
235
236#[derive(Debug, thiserror::Error)]
238pub enum ExtractError {
239 #[error("corrupt archive: {0}")]
242 Corrupt(#[source] io::Error),
243 #[error("truncated archive: {0}")]
245 Truncated(#[source] io::Error),
246 #[error("the archive holds no repository: {0}")]
248 NoRepository(String),
249 #[error("extracting the archive: {0}")]
250 Io(#[source] io::Error),
251}