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