chrome_for_testing_manager/
error.rs1use crate::{Port, VersionRequest};
2use chrome_for_testing::{Platform, Version};
3use std::{
4 fmt::{Display, Formatter},
5 path::PathBuf,
6 time::Duration,
7};
8use thiserror::Error;
9use tokio::runtime::RuntimeFlavor;
10
11pub type Result<T> = std::result::Result<T, rootcause::Report<ChromeForTestingManagerError>>;
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26#[non_exhaustive]
27pub enum ChromeForTestingArtifact {
28 Chrome,
30
31 ChromeDriver,
33}
34
35impl Display for ChromeForTestingArtifact {
36 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
37 match self {
38 Self::Chrome => f.write_str("chrome"),
39 Self::ChromeDriver => f.write_str("chromedriver"),
40 }
41 }
42}
43
44#[derive(Debug, Error)]
46#[non_exhaustive]
47pub enum ChromeForTestingManagerError {
48 #[error("chromedriver requires a multi-threaded Tokio runtime; detected {runtime_flavor:?}")]
51 UnsupportedRuntime {
52 runtime_flavor: RuntimeFlavor,
54 },
55
56 #[error("unsupported chrome-for-testing platform")]
58 UnsupportedPlatform,
59
60 #[error("failed to determine cache directory; is $HOME set?")]
63 DetermineCacheDir,
64
65 #[error("failed to create cache directory {}", .cache_dir.display())]
67 CreateCacheDir {
68 cache_dir: PathBuf,
70 },
71
72 #[error("failed to remove cache directory {}", .cache_dir.display())]
74 RemoveCacheDir {
75 cache_dir: PathBuf,
77 },
78
79 #[error("failed to recreate cache directory {}", .cache_dir.display())]
81 RecreateCacheDir {
82 cache_dir: PathBuf,
84 },
85
86 #[error("failed to request versions for {version_request:?}")]
88 RequestVersions {
89 version_request: VersionRequest,
91 },
92
93 #[error("could not determine a version for {version_request:?}")]
95 NoMatchingVersion {
96 version_request: VersionRequest,
98 },
99
100 #[error("no chrome download for version {version} on {platform}")]
102 NoChromeDownload {
103 version: Version,
105 platform: Platform,
107 },
108
109 #[error("no chromedriver download for version {version} on {platform}")]
111 NoChromedriverDownload {
112 version: Version,
114 platform: Platform,
116 },
117
118 #[error("failed to create platform directory {}", .platform_dir.display())]
120 CreatePlatformDir {
121 platform_dir: PathBuf,
123 },
124
125 #[error("failed to download {artifact} from {url}")]
128 Download {
129 artifact: ChromeForTestingArtifact,
131 url: String,
133 },
134
135 #[error("failed to create {artifact} download file {}", .path.display())]
137 CreateDownloadFile {
138 artifact: ChromeForTestingArtifact,
140 path: PathBuf,
142 },
143
144 #[error("failed to write {artifact} download chunk")]
146 WriteDownloadFile {
147 artifact: ChromeForTestingArtifact,
149 },
150
151 #[error("failed to flush {artifact} download file")]
153 FlushDownloadFile {
154 artifact: ChromeForTestingArtifact,
156 },
157
158 #[error(
160 "{artifact} download timed out after {consecutive_stalls} consecutive stalls of {chunk_timeout:?}"
161 )]
162 DownloadStalled {
163 artifact: ChromeForTestingArtifact,
165 consecutive_stalls: u32,
167 chunk_timeout: Duration,
169 },
170
171 #[error("failed to open downloaded ZIP archive {}", .path.display())]
173 OpenDownloadedZip {
174 path: PathBuf,
176 },
177
178 #[error("downloaded file {} is not a valid ZIP archive", .path.display())]
180 InvalidZip {
181 path: PathBuf,
183 },
184
185 #[error(
187 "downloaded ZIP archive {} decompressed size {size} exceeds safety limit {max_size}",
188 .path.display()
189 )]
190 ZipTooLarge {
191 path: PathBuf,
193 size: u128,
195 max_size: u128,
197 },
198
199 #[error(
201 "failed to extract ZIP archive {} to {}",
202 .path.display(),
203 .unpack_dir.display()
204 )]
205 ExtractZip {
206 path: PathBuf,
208 unpack_dir: PathBuf,
210 },
211
212 #[error("failed to remove downloaded ZIP archive {}", .path.display())]
214 RemoveDownloadedZip {
215 path: PathBuf,
217 },
218
219 #[error("failed to spawn chromedriver process {}", .path.display())]
222 SpawnChromedriver {
223 path: PathBuf,
225 },
226
227 #[error("failed while waiting for chromedriver {} to start", .path.display())]
229 WaitForChromedriverStartup {
230 path: PathBuf,
232 },
233
234 #[error("failed to terminate chromedriver process on port {port}")]
236 TerminateChromedriver {
237 port: Port,
239 },
240
241 #[error(
244 "failed to prepare Chrome capabilities for {}",
245 .chrome_executable.display()
246 )]
247 PrepareChromeCapabilities {
248 chrome_executable: PathBuf,
250 },
251
252 #[error("failed to configure Chrome capabilities")]
254 ConfigureSessionCapabilities,
255
256 #[error("failed to start WebDriver session on port {port}")]
258 StartWebDriverSession {
259 port: Port,
261 },
262
263 #[error("session callback failed")]
265 RunSessionCallback,
266
267 #[error("failed to quit WebDriver session")]
269 QuitSession,
270}