cobble_core/error/
cobble_error.rs1use crate::error::{InstallationError, LaunchError};
2
3pub type CobbleResult<T> = Result<T, CobbleError>;
5
6#[derive(Debug, thiserror::Error)]
8pub enum CobbleError {
9 #[error("Version '{0}' is not a valid minecraft version")]
11 InvalidVersion(String),
12 #[error("Instance is not marked as fully installed")]
14 NotInstalled,
15 #[error("{0}")]
17 Installation(InstallationError),
18 #[error("{0}")]
20 Launch(LaunchError),
21 #[error("{0}")]
23 Io(std::io::Error),
24 #[error("Deserialization/Serialization: {0}")]
26 Serde(serde_json::Error),
27 #[error("{0}")]
29 DownloadMetadata(reqwest::Error),
30 #[error("{0}")]
32 TokioJoinError(tokio::task::JoinError),
33
34 #[cfg_attr(
36 doc_cfg,
37 doc(cfg(any(
38 feature = "log-files",
39 feature = "resourcepacks",
40 feature = "loader-mods"
41 )))
42 )]
43 #[cfg(any(
44 feature = "log-files",
45 feature = "resourcepacks",
46 feature = "loader-mods"
47 ))]
48 #[error("{0}")]
49 Zip(async_zip::error::ZipError),
50
51 #[cfg_attr(doc_cfg, doc(cfg(feature = "internal-nbt")))]
53 #[cfg(feature = "internal-nbt")]
54 #[error("{0}")]
55 NbtSerde(fastnbt::error::Error),
56
57 #[cfg_attr(doc_cfg, doc(cfg(feature = "internal-base64")))]
59 #[cfg(feature = "internal-base64")]
60 #[error("{0}")]
61 Base64Decode(base64::DecodeError),
62
63 #[cfg_attr(doc_cfg, doc(cfg(any(feature = "save-games"))))]
65 #[cfg(any(feature = "save-games"))]
66 #[error("Import archive is missing a marker file")]
67 MissingMarkerFile,
68}
69
70impl From<InstallationError> for CobbleError {
71 fn from(err: InstallationError) -> Self {
72 Self::Installation(err)
73 }
74}
75
76impl From<LaunchError> for CobbleError {
77 fn from(err: LaunchError) -> Self {
78 Self::Launch(err)
79 }
80}
81
82impl From<std::io::Error> for CobbleError {
83 fn from(err: std::io::Error) -> Self {
84 Self::Io(err)
85 }
86}
87
88impl From<serde_json::Error> for CobbleError {
89 fn from(err: serde_json::Error) -> Self {
90 Self::Serde(err)
91 }
92}
93
94impl From<reqwest::Error> for CobbleError {
95 fn from(err: reqwest::Error) -> Self {
96 Self::DownloadMetadata(err)
97 }
98}
99
100impl From<tokio::task::JoinError> for CobbleError {
101 fn from(err: tokio::task::JoinError) -> Self {
102 Self::TokioJoinError(err)
103 }
104}
105
106#[cfg(any(
107 feature = "log-files",
108 feature = "resourcepacks",
109 feature = "loader-mods"
110))]
111impl From<async_zip::error::ZipError> for CobbleError {
112 fn from(err: async_zip::error::ZipError) -> Self {
113 Self::Zip(err)
114 }
115}
116
117#[cfg(feature = "internal-nbt")]
118impl From<fastnbt::error::Error> for CobbleError {
119 fn from(err: fastnbt::error::Error) -> Self {
120 Self::NbtSerde(err)
121 }
122}
123
124#[cfg(feature = "internal-base64")]
125impl From<base64::DecodeError> for CobbleError {
126 fn from(err: base64::DecodeError) -> Self {
127 Self::Base64Decode(err)
128 }
129}