Skip to main content

minecraft_java_rs_core/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum LaunchError {
5    #[error("no authenticator provided")]
6    NoAuthenticator,
7
8    #[error("no internet connection and no local cache available")]
9    NoInternetNoCache,
10
11    #[error("game data not ready: call download_game first")]
12    GameDataNotReady,
13
14    #[error("corrupt local cache: {0}")]
15    CorruptCache(String),
16
17    #[error("version '{0}' not found in Mojang manifest")]
18    VersionNotFound(String),
19
20    #[error("Java process error: {0}")]
21    ProcessError(String),
22
23    #[error("archive error: {0}")]
24    Archive(String),
25
26    #[error("download error: {0}")]
27    Download(#[from] DownloadError),
28
29    #[error("loader error: {0}")]
30    Loader(#[from] LoaderError),
31
32    #[error("IO error: {0}")]
33    Io(#[from] std::io::Error),
34
35    #[error("JSON error: {0}")]
36    Json(#[from] serde_json::Error),
37
38    // For HTTP calls outside the downloader (version manifest, asset index, etc.)
39    #[error("HTTP error: {0}")]
40    Http(#[from] reqwest::Error),
41
42    #[error("invalid data: {0}")]
43    InvalidData(String),
44}
45
46#[derive(Debug, Error)]
47pub enum LoaderError {
48    #[error("installer download failed: {0}")]
49    InstallerDownloadFailed(String),
50
51    #[error("installer JAR not found at: {0}")]
52    InstallerNotFound(String),
53
54    // install_profile.json missing from the installer JAR
55    #[error("install_profile.json not found in installer JAR")]
56    ProfileNotFound,
57
58    #[error("forge processor '{processor}' failed with exit code {code:?}")]
59    ProcessorFailed {
60        processor: String,
61        code: Option<i32>,
62    },
63
64    #[error("loader API error: {0}")]
65    ApiError(String),
66
67    #[error("loader version not found: {0}")]
68    VersionNotFound(String),
69
70    #[error("archive error: {0}")]
71    Archive(String),
72
73    #[error("IO error: {0}")]
74    Io(#[from] std::io::Error),
75
76    #[error("HTTP error: {0}")]
77    Http(#[from] reqwest::Error),
78
79    #[error("JSON error: {0}")]
80    Json(#[from] serde_json::Error),
81}
82
83#[derive(Debug, Error)]
84pub enum DownloadError {
85    #[error("checksum mismatch for '{file}': expected {expected}, got {actual}")]
86    ChecksumMismatch {
87        file: String,
88        expected: String,
89        actual: String,
90    },
91
92    #[error("no mirror available for: {0}")]
93    NoMirrorAvailable(String),
94
95    #[error("request timed out")]
96    Timeout,
97
98    /// The request never reached the server (DNS failure, unreachable route,
99    /// connection reset/timeout). Carries a human description of the
100    /// transport-level cause instead of reqwest's opaque "error sending
101    /// request for url" message.
102    #[error("could not reach {url} ({detail})")]
103    Connection { url: String, detail: String },
104
105    #[error("IO error: {0}")]
106    Io(#[from] std::io::Error),
107
108    #[error("HTTP error: {0}")]
109    Http(#[from] reqwest::Error),
110}