Skip to main content

elemental_driver/
error.rs

1use std::{error::Error as StdError, io, path::PathBuf, time::SystemTimeError};
2
3#[derive(Debug, thiserror::Error)]
4#[non_exhaustive]
5pub enum Error {
6    #[error(transparent)]
7    Io(#[from] io::Error),
8
9    #[error(transparent)]
10    Json(#[from] serde_json::Error),
11
12    #[error(transparent)]
13    Xml(#[from] quick_xml::DeError),
14
15    #[error(transparent)]
16    Http(#[from] reqwest::Error),
17
18    #[error("{message}")]
19    HttpClientBuild { message: String },
20
21    #[error("unsupported driver id: '{id}'")]
22    UnsupportedDriver { id: String },
23
24    #[error("driver '{driver}' requires a loader version")]
25    LoaderVersionRequired { driver: String },
26
27    #[error(transparent)]
28    Infra(#[from] elemental_infra::error::Error),
29
30    #[error(transparent)]
31    Shared(#[from] elemental_shared::error::Error),
32
33    #[error(transparent)]
34    Storage(#[from] elemental_core::storage::Error),
35
36    #[error(transparent)]
37    Runtime(#[from] elemental_core::runtime::Error),
38
39    #[error("blocking task failed: {0}")]
40    BlockingTask(#[from] tokio::task::JoinError),
41
42    #[error(transparent)]
43    Launcher(#[from] elemental_core::launcher::Error),
44
45    #[error(transparent)]
46    SystemTime(#[from] SystemTimeError),
47
48    #[error("{context}: {url}")]
49    InvalidUrl {
50        context: String,
51        url: String,
52        #[source]
53        source: Box<dyn StdError + Send + Sync>,
54    },
55
56    #[error("{context}: {base_url} + {path}")]
57    JoinUrl {
58        context: String,
59        base_url: String,
60        path: String,
61        #[source]
62        source: Box<dyn StdError + Send + Sync>,
63    },
64
65    #[error("URL cannot be used as a path base: {url}")]
66    UrlNotPathBase { url: String },
67
68    #[error("can't map URL to a known origin: {raw_url}")]
69    UnknownOrigin { raw_url: String },
70
71    #[error("URL matches a known origin host but not a configured base path: {raw_url}")]
72    OriginBasePathMismatch { raw_url: String },
73
74    #[error("request {source_name} resource failed: {url}")]
75    RequestResource {
76        source_name: String,
77        url: String,
78        #[source]
79        source: reqwest::Error,
80    },
81
82    #[error("{source_name} returned error status: {url}")]
83    HttpStatus {
84        source_name: String,
85        url: String,
86        #[source]
87        source: reqwest::Error,
88    },
89
90    #[error("decode {source_name} resource failed: {url}")]
91    DecodeResource {
92        source_name: String,
93        url: String,
94        #[source]
95        source: reqwest::Error,
96    },
97
98    #[error("invalid {label} notation: {notation}")]
99    InvalidNotation { label: String, notation: String },
100
101    #[error("maven library '{notation}' has neither downloads nor a repository url")]
102    MavenLibraryMissingSource { notation: String },
103
104    #[error("{context} must use http or https: {url}")]
105    UnsupportedUrlScheme { context: String, url: String },
106
107    #[error("decode {source_label} maven metadata failed: {url}")]
108    DecodeMavenMetadata {
109        source_label: String,
110        url: String,
111        #[source]
112        source: quick_xml::DeError,
113    },
114
115    #[error("read version metadata failed")]
116    ReadVersionMetadata {
117        #[source]
118        source: Box<Error>,
119    },
120
121    #[error("get version name failed for '{}'", path.display())]
122    MissingVersionName { path: PathBuf },
123
124    #[error("version root has no file name: {}", path.display())]
125    MissingVersionRootFileName { path: PathBuf },
126
127    #[error("logging config not found: {}", path.display())]
128    LoggingConfigMissing { path: PathBuf },
129
130    #[error("module path argument is missing its value")]
131    ModulePathValueMissing,
132
133    #[error("resolve module path argument failed")]
134    ResolveModulePath,
135
136    #[error("version jar not found: {}", path.display())]
137    VersionJarMissing { path: PathBuf },
138
139    #[error("local version '{version}' is not prepared: {status}")]
140    VersionNotPrepared { version: String, status: String },
141
142    #[error("parse base minecraftArguments failed")]
143    ParseBaseMinecraftArguments {
144        #[source]
145        source: Box<Error>,
146    },
147
148    #[error("launcher variables serialized to a non-object JSON value")]
149    LauncherVariablesNotObject,
150
151    #[error("can't find a valid instance named '{name}'")]
152    InstanceNotFound { name: String },
153
154    #[error("{context} has no parent directory: {}", path.display())]
155    MissingParentDirectory { context: String, path: PathBuf },
156
157    #[error("installer coordinate has no file name: {notation}")]
158    InstallerCoordinateFileNameMissing { notation: String },
159
160    #[error("read persisted {family_name} install profile failed: {}", path.display())]
161    ReadPersistedInstallProfile {
162        family_name: String,
163        path: PathBuf,
164        #[source]
165        source: serde_json::Error,
166    },
167
168    #[error("read persisted {family_name} embedded version failed: {}", path.display())]
169    ReadPersistedEmbeddedVersion {
170        family_name: String,
171        path: PathBuf,
172        #[source]
173        source: serde_json::Error,
174    },
175
176    #[error("{family_name} install profile is missing minecraft version")]
177    InstallerProfileMinecraftVersionMissing { family_name: String },
178
179    #[error("{family_name} install profile is missing {loader_name} version identity")]
180    InstallerProfileLoaderVersionMissing {
181        family_name: String,
182        loader_name: String,
183    },
184
185    #[error(
186        "{family_name} installer game version '{actual}' does not match requested game version '{expected}'"
187    )]
188    InstallerGameVersionMismatch {
189        family_name: String,
190        actual: String,
191        expected: String,
192    },
193
194    #[error(
195        "{family_name} installer loader version '{actual}' does not match requested loader version '{expected}'"
196    )]
197    InstallerLoaderVersionMismatch {
198        family_name: String,
199        actual: String,
200        expected: String,
201    },
202
203    #[error("read {family_name} embedded version json failed: {path}")]
204    ReadEmbeddedVersionJson {
205        family_name: String,
206        path: String,
207        #[source]
208        source: Box<Error>,
209    },
210
211    #[error("download {family_name} installer failed")]
212    DownloadInstaller {
213        family_name: String,
214        #[source]
215        source: elemental_infra::error::Error,
216    },
217
218    #[error("read {family_name} install_profile.json from installer failed")]
219    ReadInstallerProfile {
220        family_name: String,
221        #[source]
222        source: Box<Error>,
223    },
224
225    #[error("extract {family_name} embedded maven artifacts failed")]
226    ExtractInstallerMavenArtifacts {
227        family_name: String,
228        #[source]
229        source: Box<Error>,
230    },
231
232    #[error(
233        "{family_name} installer is missing an embedded version json; launchable {family_name} preparation is not available"
234    )]
235    InstallerEmbeddedVersionMissing { family_name: String },
236
237    #[error("decode {family_name} embedded version json failed")]
238    DecodeEmbeddedVersion {
239        family_name: String,
240        #[source]
241        source: serde_json::Error,
242    },
243
244    #[error("local {family_name} instance '{instance}' is not fully prepared: {status}")]
245    InstallerNotPrepared {
246        family_name: String,
247        instance: String,
248        status: String,
249    },
250
251    #[error("get {family_name} instance name failed for '{}'", path.display())]
252    MissingInstanceName { family_name: String, path: PathBuf },
253
254    #[error("download {family_name} install profile libraries failed")]
255    DownloadInstallerProfileLibraries {
256        family_name: String,
257        #[source]
258        source: elemental_infra::error::Error,
259    },
260
261    #[error(
262        "{family_name} client processors completed without producing the expected client artifacts"
263    )]
264    ProcessorOutputsMissing { family_name: String },
265
266    #[error("unknown {family_name} processor variable: {key}")]
267    UnknownProcessorVariable { family_name: String, key: String },
268
269    #[error("run {family_name} processor failed: {processor}")]
270    RunProcessor {
271        family_name: String,
272        processor: String,
273        #[source]
274        source: io::Error,
275    },
276
277    // ProcessorFailure is large; boxing it keeps every Result<T, Error> small.
278    #[error(transparent)]
279    ProcessorFailed(Box<ProcessorFailure>),
280
281    #[error("jar manifest is missing Main-Class: {}", path.display())]
282    JarMainClassMissing { path: PathBuf },
283
284    #[error("resolve current directory failed for {}", path.display())]
285    CurrentDirectory {
286        path: PathBuf,
287        #[source]
288        source: io::Error,
289    },
290
291    #[error("asset hash is too short: '{hash}'")]
292    AssetHashTooShort { hash: String },
293
294    #[error("can't find vanilla version named '{game_version}'")]
295    VanillaVersionNotFound { game_version: String },
296
297    #[error("rewrite {family_name} upstream url failed for '{raw_url}'")]
298    RewriteUpstream {
299        family_name: String,
300        raw_url: String,
301        #[source]
302        source: Box<Error>,
303    },
304
305    #[error("can't find LiteLoader Minecraft version '{game_version}'")]
306    LiteLoaderMinecraftVersionNotFound { game_version: String },
307
308    #[error(
309        "can't find LiteLoader loader version '{loader_version}' for Minecraft '{game_version}'"
310    )]
311    LiteLoaderLoaderVersionNotFound {
312        loader_version: String,
313        game_version: String,
314    },
315
316    #[error("LiteLoader library '{library}' does not declare a supported repository")]
317    LiteLoaderLibraryRepositoryMissing { library: String },
318
319    #[error("LiteLoader snapshot library '{library}' does not declare a repository")]
320    LiteLoaderSnapshotRepositoryMissing { library: String },
321
322    #[error("can't find Rift release asset named '{asset_name}'")]
323    RiftReleaseAssetNotFound { asset_name: String },
324
325    #[error("Rift release tag has no loader version: '{tag_name}'")]
326    RiftReleaseTagMissingLoaderVersion { tag_name: String },
327
328    #[error("read embedded Rift profile failed from '{asset_name}'")]
329    ReadRiftProfile {
330        asset_name: String,
331        #[source]
332        source: elemental_infra::error::Error,
333    },
334
335    #[error("decode embedded Rift profile failed")]
336    DecodeRiftProfile {
337        #[source]
338        source: serde_json::Error,
339    },
340
341    #[error(
342        "Rift loader '{loader_version}' targets Minecraft '{actual}' but '{requested}' was requested"
343    )]
344    RiftGameVersionMismatch {
345        loader_version: String,
346        actual: String,
347        requested: String,
348    },
349
350    #[error("trailing escape in argument string")]
351    TrailingArgumentEscape,
352
353    #[error("unterminated quoted argument string with quote {quote}")]
354    UnterminatedArgumentQuote { quote: char },
355}
356
357#[derive(Debug, thiserror::Error)]
358#[non_exhaustive]
359#[error(
360    "{family_name} processor failed: processor={processor}, java={java}, main_class={main_class}, classpath={classpath}, args={args:?}, exit_status={exit_status:?}, stdout=\n{stdout}\nstderr=\n{stderr}"
361)]
362pub struct ProcessorFailure {
363    pub family_name: String,
364    pub processor: String,
365    pub java: String,
366    pub main_class: String,
367    pub classpath: String,
368    pub args: Vec<String>,
369    pub exit_status: Option<i32>,
370    pub stdout: String,
371    pub stderr: String,
372}
373
374impl Error {
375    pub(crate) fn invalid_url(
376        context: impl Into<String>,
377        url: impl Into<String>,
378        source: impl StdError + Send + Sync + 'static,
379    ) -> Self {
380        Self::InvalidUrl {
381            context: context.into(),
382            url: url.into(),
383            source: Box::new(source),
384        }
385    }
386
387    pub(crate) fn join_url(
388        context: impl Into<String>,
389        base_url: impl Into<String>,
390        path: impl Into<String>,
391        source: impl StdError + Send + Sync + 'static,
392    ) -> Self {
393        Self::JoinUrl {
394            context: context.into(),
395            base_url: base_url.into(),
396            path: path.into(),
397            source: Box::new(source),
398        }
399    }
400}
401
402pub type Result<T> = std::result::Result<T, Error>;