mc_launcher_core/error.rs
1//! Error types returned by the launcher facade and lower-level modules.
2
3use std::path::PathBuf;
4
5use crate::loader::LoaderKind;
6
7/// Crate-wide result type.
8pub type Result<T> = std::result::Result<T, LauncherError>;
9
10/// Errors produced by install, metadata, IO, and launch-command operations.
11#[derive(Debug, thiserror::Error)]
12pub enum LauncherError {
13 /// HTTP or request-building failure.
14 #[error("network error: {source}")]
15 Network {
16 /// Original reqwest error.
17 #[from]
18 source: reqwest::Error,
19 },
20 /// Filesystem failure.
21 #[error("io error: {source}")]
22 Io {
23 /// Original IO error.
24 #[from]
25 source: std::io::Error,
26 },
27 /// JSON parse or serialization failure.
28 #[error("json error: {source}")]
29 Json {
30 /// Original serde_json error.
31 #[from]
32 source: serde_json::Error,
33 },
34 /// ZIP archive failure.
35 #[error("zip error: {source}")]
36 Zip {
37 /// Original zip error.
38 #[from]
39 source: zip::result::ZipError,
40 },
41 /// Requested version id was not found or was not valid in context.
42 #[error("invalid version id: {id}")]
43 InvalidVersionId {
44 /// Requested version id.
45 id: String,
46 },
47 /// Current or requested platform cannot be handled.
48 #[error("unsupported platform: {os}/{arch}")]
49 UnsupportedPlatform {
50 /// Operating system name.
51 os: String,
52 /// CPU architecture name.
53 arch: String,
54 },
55 /// A downloaded file did not match its expected checksum.
56 #[error("checksum mismatch for {path}: expected {expected}, got {actual}")]
57 ChecksumMismatch {
58 /// File that failed validation.
59 path: PathBuf,
60 /// Expected checksum.
61 expected: String,
62 /// Actual checksum.
63 actual: String,
64 },
65 /// A joined path escaped the intended base directory.
66 #[error("unsafe path {path} escapes base {base}")]
67 UnsafePath {
68 /// Expected base directory.
69 base: PathBuf,
70 /// Path that escaped the base directory.
71 path: PathBuf,
72 },
73 /// Maven coordinate parsing failed.
74 #[error("invalid maven coordinate: {coordinate}")]
75 InvalidMavenCoordinate {
76 /// Coordinate string that could not be parsed.
77 coordinate: String,
78 },
79 /// A requested loader version could not be resolved.
80 #[error("{loader:?} loader version not found: {version}")]
81 LoaderVersionNotFound {
82 /// Loader family being resolved.
83 loader: LoaderKind,
84 /// Requested loader version selector or value.
85 version: String,
86 },
87 /// A Forge or NeoForge installer process failed.
88 #[error("{loader:?} installer failed with status {status:?}")]
89 InstallerFailed {
90 /// Loader family whose installer failed.
91 loader: LoaderKind,
92 /// Process exit status code, if available.
93 status: Option<i32>,
94 },
95 /// Required metadata was missing from a version/profile document.
96 #[error("missing field {field} in {context}")]
97 MissingField {
98 /// Metadata document or profile being read.
99 context: String,
100 /// Missing field name.
101 field: String,
102 },
103 /// Miscellaneous error with a caller-facing message.
104 #[error("{message}")]
105 Other {
106 /// Error message.
107 message: String,
108 },
109}