1use std::{io, path::PathBuf};
2
3use elemental_driver::families::version_json::PatchMode;
4
5#[derive(Debug, thiserror::Error)]
6#[non_exhaustive]
7pub enum Error {
8 #[error(transparent)]
9 Io(#[from] io::Error),
10
11 #[error(transparent)]
12 Json(#[from] serde_json::Error),
13
14 #[error(transparent)]
15 Driver(#[from] elemental_driver::error::Error),
16
17 #[error(transparent)]
18 Origin(#[from] elemental_core::url::OriginError),
19
20 #[cfg(any(feature = "liteloader", feature = "authlib-injector"))]
21 #[error(transparent)]
22 HttpRequest(#[from] elemental_core::http::HttpRequestError),
23
24 #[error(transparent)]
25 Infra(#[from] elemental_infra::error::Error),
26
27 #[error(transparent)]
28 Shared(#[from] elemental_shared::error::Error),
29
30 #[error(transparent)]
31 Storage(#[from] elemental_core::storage::Error),
32
33 #[error("addon '{id}' is incompatible with this instance: {reason}")]
34 Incompatible { id: String, reason: String },
35
36 #[error("addon '{id}' requires an explicit version")]
37 VersionRequired { id: String },
38
39 #[error("managed addon file path escapes instance directory: '{}'", path.display())]
40 UnsafeManagedPath { path: PathBuf },
41
42 #[error("addon '{id}' does not support {requested:?} patch mode (supports {supported})")]
43 PatchModeUnsupported {
44 id: String,
45 requested: PatchMode,
46 supported: String,
47 },
48
49 #[error(
50 "addon '{id}' cannot use physical patching when instance policy is {instance_policy:?}"
51 )]
52 PatchModeDisallowedByInstance {
53 id: String,
54 instance_policy: PatchMode,
55 },
56
57 #[error("addon '{id}' is not installed on this instance")]
58 AddonNotInstalled { id: String },
59
60 #[error("cannot reorder addon '{id}': not installed on this instance")]
61 UnknownAddonInOrder { id: String },
62
63 #[cfg(feature = "liteloader")]
64 #[error("can't find LiteLoader Minecraft version '{game_version}'")]
65 LiteLoaderMinecraftVersionNotFound { game_version: String },
66
67 #[cfg(feature = "liteloader")]
68 #[error(
69 "can't find LiteLoader loader version '{loader_version}' for Minecraft '{game_version}'"
70 )]
71 LiteLoaderLoaderVersionNotFound {
72 loader_version: String,
73 game_version: String,
74 },
75
76 #[cfg(feature = "liteloader")]
77 #[error("LiteLoader library '{library}' does not declare a supported repository")]
78 LiteLoaderLibraryRepositoryMissing { library: String },
79
80 #[cfg(feature = "liteloader")]
81 #[error("LiteLoader snapshot library '{library}' does not declare a repository")]
82 LiteLoaderSnapshotRepositoryMissing { library: String },
83
84 #[cfg(feature = "authlib-injector")]
85 #[error(transparent)]
86 AuthlibInjectorDistribution(#[from] nidhogg::error::NidhoggError),
87
88 #[cfg(feature = "authlib-injector")]
89 #[error("authlib-injector version '{version}' was not found in distribution manifest")]
90 AuthlibInjectorVersionNotFound { version: String },
91
92 #[cfg(feature = "authlib-injector")]
93 #[error("authlib-injector download completed but '{}' is missing", path.display())]
94 AuthlibInjectorMissing { path: PathBuf },
95
96 #[cfg(feature = "authlib-injector")]
97 #[error(
98 "authlib-injector checksum mismatch for '{}': expected {expected}, got {actual}",
99 path.display()
100 )]
101 AuthlibInjectorChecksum {
102 path: PathBuf,
103 expected: String,
104 actual: String,
105 },
106}
107
108pub type Result<T> = std::result::Result<T, Error>;