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 is empty")]
73 Empty,
74 #[error("the SSH key could not be written: {0}")]
75 File(#[source] io::Error),
76 #[error("the SSH key path cannot be quoted for the shell: {0}")]
77 Path(#[from] shlex::QuoteError),
78}
79
80#[derive(Debug, thiserror::Error)]
82pub enum LsRemoteError {
83 #[error(transparent)]
84 SshKey(#[from] SshKeyError),
85 #[error(transparent)]
86 Sts(#[from] StsError),
87 #[error(transparent)]
88 Access(#[from] HttpsAccessError),
89 #[error(transparent)]
90 Git(#[from] GitCallError),
91}
92
93#[derive(Debug, thiserror::Error)]
95pub enum SshHostError {
96 #[error("Invalid ssh url: expected user@host:path or ssh://user@host[:port]/path")]
98 Malformed,
99 #[error("Could not resolve the hostname {host}: {source}")]
100 Unresolved {
101 host: String,
102 #[source]
103 source: io::Error,
104 },
105 #[error("No IP addresses resolved for hostname: {host}")]
106 NoAddresses { host: String },
107 #[error("SSH host validation failed for {host}: {reason}")]
108 Local {
109 host: String,
110 reason: crate::local_address::LocalAddress,
111 },
112}
113
114#[derive(Debug, thiserror::Error)]
116pub enum StsError {
117 #[error("STS refused the role {arn}: {code}: {message}")]
119 Refused {
120 arn: String,
121 code: String,
122 message: String,
123 },
124 #[error("STS took too long to connect for the role {arn}: {reason}")]
125 ConnectTimeout { arn: String, reason: String },
126 #[error("STS took too long to answer the role {arn}: {reason}")]
128 ReadTimeout { arn: String, reason: String },
129 #[error("STS closed the connection for the role {arn}: {reason}")]
131 ConnectionClosed { arn: String, reason: String },
132 #[error("STS could not be connected to for the role {arn}: {reason}")]
134 NoConnection { arn: String, reason: String },
135 #[error("STS could not be asked for the role {arn}: {reason}")]
137 Unreachable { arn: String, reason: String },
138 #[error("STS answered the role {arn} without credentials")]
139 NoCredentials { arn: String },
140}
141
142#[derive(Debug, thiserror::Error)]
143pub enum GitCallError {
144 #[error("git {command} could not start: {source}")]
145 NotStarted {
146 command: &'static str,
147 source: io::Error,
148 },
149 #[error("git {command} did not finish within {after:?}")]
150 TimedOut {
151 command: &'static str,
152 after: Duration,
153 },
154 #[error("git {command} exited with {status}: {stderr}")]
156 Refused {
157 command: &'static str,
158 status: ExitStatus,
159 stderr: String,
160 },
161 #[error("git {command} got an argument with an embedded null byte")]
163 NullByte { command: &'static str },
164 #[error("git {command} printed something unreadable: {reason}")]
165 Malformed {
166 command: &'static str,
167 reason: String,
168 },
169}
170
171#[derive(Debug, thiserror::Error)]
173pub enum DownloadError {
174 #[error("writing the archive: {0}")]
177 Write(#[source] io::Error),
178 #[error(transparent)]
179 Fetch(#[from] FetchError),
180 #[error(transparent)]
181 Extract(#[from] ExtractError),
182 #[error(transparent)]
184 Reset(#[from] GitCallError),
185 #[error("pruning the working tree: {0}")]
186 Prune(#[from] PruneError),
187 #[error("placing the repository: {0}")]
190 Place(#[source] io::Error),
191}
192
193#[derive(Debug, thiserror::Error)]
195pub enum FetchError {
196 #[error("invalid url {url}: {reason}")]
197 InvalidUrl { url: String, reason: String },
198 #[error("not an http url: {0}")]
199 NonHttpUrl(String),
200 #[error("could not connect: {0}")]
202 Connect(#[source] reqwest::Error),
203 #[error("connecting timed out: {0}")]
204 ConnectTimeout(#[source] reqwest::Error),
205 #[error("no response in time: {0}")]
207 Timeout(#[source] reqwest::Error),
208 #[error("the server disconnected: {0}")]
210 Disconnected(#[source] reqwest::Error),
211 #[error("the socket failed: {source}")]
214 Socket {
215 reset: bool,
216 errno: Option<i32>,
217 source: reqwest::Error,
218 },
219 #[error("malformed response: {0}")]
220 Malformed(#[source] reqwest::Error),
221 #[error("the server answered {0}")]
222 Status(reqwest::StatusCode),
223 #[error("the body was cut: {0}")]
225 BodyCut(#[source] reqwest::Error),
226 #[error("the body did not arrive in time: {0}")]
228 BodyTimeout(#[source] reqwest::Error),
229 #[error("the request failed: {0}")]
230 Other(#[source] reqwest::Error),
231}
232
233#[derive(Debug, thiserror::Error)]
235pub enum ExtractError {
236 #[error("corrupt archive: {0}")]
239 Corrupt(#[source] io::Error),
240 #[error("truncated archive: {0}")]
242 Truncated(#[source] io::Error),
243 #[error("the archive holds no repository: {0}")]
245 NoRepository(String),
246 #[error("extracting the archive: {0}")]
247 Io(#[source] io::Error),
248}