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 { processor: String, code: Option<i32> },
60
61    #[error("loader API error: {0}")]
62    ApiError(String),
63
64    #[error("loader version not found: {0}")]
65    VersionNotFound(String),
66
67    #[error("archive error: {0}")]
68    Archive(String),
69
70    #[error("IO error: {0}")]
71    Io(#[from] std::io::Error),
72
73    #[error("HTTP error: {0}")]
74    Http(#[from] reqwest::Error),
75
76    #[error("JSON error: {0}")]
77    Json(#[from] serde_json::Error),
78}
79
80#[derive(Debug, Error)]
81pub enum DownloadError {
82    #[error("checksum mismatch for '{file}': expected {expected}, got {actual}")]
83    ChecksumMismatch {
84        file: String,
85        expected: String,
86        actual: String,
87    },
88
89    #[error("no mirror available for: {0}")]
90    NoMirrorAvailable(String),
91
92    #[error("request timed out")]
93    Timeout,
94
95    #[error("IO error: {0}")]
96    Io(#[from] std::io::Error),
97
98    #[error("HTTP error: {0}")]
99    Http(#[from] reqwest::Error),
100}