mcdata_rs/
error.rs

1pub use crate::version::Edition;
2use std::path::PathBuf;
3use thiserror::Error; // Re-export Edition for convenience
4
5/// Represents errors that can occur within the mcdata-rs library.
6#[derive(Error, Debug)]
7pub enum McDataError {
8    // Errors related to version resolution.
9    #[error("Version string '{0}' is invalid or unsupported")]
10    InvalidVersion(String),
11
12    #[error("Version '{mc_version}' (major: {major_version}) not found for edition {edition:?}")]
13    VersionNotFound {
14        mc_version: String,
15        major_version: String,
16        edition: Edition,
17    },
18
19    // Errors related to finding and loading data files.
20    #[error(
21        "Data key '{data_key}' not found in dataPaths.json for version {mc_version} ({edition:?})"
22    )]
23    DataPathNotFound {
24        mc_version: String, // The major version used for lookup (e.g., "1.18")
25        edition: Edition,
26        data_key: String, // The data key (e.g., "blocks")
27    },
28
29    #[error("Data file not found for key '{data_key}' at expected path pattern: {path:?}")]
30    DataFileNotFound { data_key: String, path: PathBuf },
31
32    #[error("I/O error accessing path {path:?}: {source}")]
33    IoError {
34        path: PathBuf,
35        #[source]
36        source: std::io::Error,
37    },
38
39    #[error("Failed to parse JSON file {path:?}: {source}")]
40    JsonParseError {
41        path: PathBuf,
42        #[source]
43        source: serde_json::Error,
44    },
45
46    // Errors related to the download and caching mechanism.
47    #[error("Could not determine a valid cache directory for application data")]
48    CacheDirNotFound,
49
50    #[error("Failed to download minecraft-data: {0}")]
51    DownloadError(String), // Wraps errors from reqwest or response handling.
52
53    #[error("Failed to process downloaded archive: {0}")]
54    ArchiveError(String), // Wraps errors from the zip library or I/O during extraction.
55
56    #[error("Failed to verify data after download/extraction in {0:?}")]
57    DownloadVerificationFailed(PathBuf), // Indicates expected files/dirs were missing post-extraction.
58
59    // Other internal or unexpected errors.
60    #[error("Internal error: {0}")]
61    Internal(String), // For unexpected states or logic errors.
62
63    #[error("Cached operation failed previously: {0}")]
64    CachedError(String), // Indicates a cached OnceCell holds a previous error result.
65}