diff options
Diffstat (limited to '')
| -rw-r--r-- | src/errors.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/errors.rs b/src/errors.rs index c167733..b98ae2d 100644 --- a/src/errors.rs +++ b/src/errors.rs | |||
| @@ -1,20 +1,31 @@ | |||
| 1 | use std::{fmt, io}; | 1 | use std::{fmt, io}; |
| 2 | 2 | ||
| 3 | use fmt::{Display, Formatter, Result}; | ||
| 4 | use zip::result::ZipError; | ||
| 5 | |||
| 6 | /// Represents all possible errors that can occur in the DML launcher. | ||
| 7 | /// | ||
| 8 | /// This enum centralizes error handling for the entire application, | ||
| 9 | /// wrapping various underlying error types from I/O, HTTP requests, | ||
| 10 | /// JSON parsing, ZIP extraction, configuration issues, and runtime errors. | ||
| 3 | #[allow(dead_code)] | 11 | #[allow(dead_code)] |
| 4 | #[derive(Debug)] | 12 | #[derive(Debug)] |
| 5 | pub enum McError { | 13 | pub enum McError { |
| 6 | Io(io::Error), | 14 | Io(io::Error), |
| 7 | Http(reqwest::Error), | 15 | Http(reqwest::Error), |
| 8 | Json(serde_json::Error), | 16 | Json(serde_json::Error), |
| 9 | Zip(zip::result::ZipError), | 17 | Zip(ZipError), |
| 10 | Config(String), | 18 | Config(String), |
| 11 | ShaMismatch(String), | 19 | ShaMismatch(String), |
| 12 | Process(String), | 20 | Process(String), |
| 13 | Runtime(String), // ← NEW | 21 | Runtime(String), |
| 14 | } | 22 | } |
| 15 | 23 | ||
| 16 | impl fmt::Display for McError { | 24 | impl Display for McError { |
| 17 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } | 25 | /// Formats the error for user-friendly display. |
| 26 | /// | ||
| 27 | /// Currently, it uses the `Debug` format for simplicity. | ||
| 28 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "{:?}", self) } | ||
| 18 | } | 29 | } |
| 19 | 30 | ||
| 20 | impl From<io::Error> for McError { | 31 | impl From<io::Error> for McError { |
| @@ -29,6 +40,6 @@ impl From<serde_json::Error> for McError { | |||
| 29 | fn from(e: serde_json::Error) -> Self { Self::Json(e) } | 40 | fn from(e: serde_json::Error) -> Self { Self::Json(e) } |
| 30 | } | 41 | } |
| 31 | 42 | ||
| 32 | impl From<zip::result::ZipError> for McError { | 43 | impl From<ZipError> for McError { |
| 33 | fn from(e: zip::result::ZipError) -> Self { Self::Zip(e) } | 44 | fn from(e: ZipError) -> Self { Self::Zip(e) } |
| 34 | } | 45 | } |
