sb3_decoder/
error.rs

1//! Error types for the application.
2//!
3//! This module defines custom error types to handle various error scenarios
4//! that may occur during the decoding process.
5
6use thiserror::Error;
7
8/// Represents errors that can occur during the decoding process.
9///
10/// This enum encapsulates errors from ZIP handling, JSON parsing, and I/O operations.
11/// Each variant provides context about the specific error encountered.
12#[derive(Error, Debug)]
13pub enum DecodeError {
14    /// Error related to ZIP file handling.
15    #[error("Zip error: {0}")]
16    Zip(#[from] zip::result::ZipError),
17
18    /// Error related to JSON parsing.
19    #[error("JSON error: {0}")]
20    Json(#[from] serde_json::Error),
21
22    /// Error related to I/O operations.
23    #[error("IO error: {0}")]
24    Io(#[from] std::io::Error),
25
26    /// Error indicating that something was expected but not found.
27    #[error("Expected item not found: {0}")]
28    NotFound(String),
29
30    /// Error indicating an invalid format or data.
31    #[error("Invalid data: {0}")]
32    InvalidData(String),
33
34    /// Error indicating something was unknown or unexpected.
35    #[error("Unknown {0}: {1}")]
36    Unknown(String, String),
37}
38
39/// Represents errors that can occur during the building of a decoder.
40///
41/// This enum encapsulates errors related to invalid configurations or missing parameters.
42#[derive(Error, Debug)]
43pub enum BuilderError {
44    /// Error indicating that no source was specified for the decoder.
45    #[error("No source specified for the decoder.")]
46    NoSource,
47
48    /// Error indicating that reading the specified file failed.
49    #[error("Failed to read the specified file: {0}")]
50    FileRead(#[from] std::io::Error),
51
52    /// Error that contains a DecodeError.
53    #[error("Decoding error: {0}")]
54    Decode(#[from] DecodeError),
55}