wow_alchemy_m2/
error.rs

1use std::io;
2use thiserror::Error;
3use wow_alchemy_data::error::WowDataError;
4
5use crate::MD20Version;
6
7/// Error types for M2 model parsing and processing
8#[derive(Error, Debug)]
9pub enum M2Error {
10    /// I/O Error during reading or writing
11    #[error("I/O error: {0}")]
12    Io(#[from] io::Error),
13
14    #[error("wow-alchemy-data error: {0}")]
15    WowData(#[from] wow_alchemy_data::error::WowDataError),
16
17    /// Invalid magic number in the file header
18    #[error("Invalid magic number: expected '{expected}', got '{actual}'")]
19    InvalidMagic { expected: String, actual: String },
20
21    /// Unsupported file version
22    #[error("Unsupported version: {0}")]
23    UnsupportedVersion(String),
24
25    /// Unsupported numeric file version
26    #[error("Unsupported numeric version: {0}")]
27    UnsupportedNumericVersion(u32),
28
29    /// Unsupported version conversion
30    #[error("Unsupported conversion to version: {0}")]
31    UnsupportedVersionWriting(MD20Version),
32
33    /// Error during parsing
34    #[error("Parse error: {0}")]
35    ParseError(String),
36
37    /// Error during validation
38    #[error("Validation error: {0}")]
39    ValidationError(String),
40
41    /// Error during version conversion
42    #[error("Conversion error: cannot convert from version {from} to {to}: {reason}")]
43    ConversionError { from: u32, to: u32, reason: String },
44
45    /// Chunk error: missing expected chunk or invalid chunk
46    #[error("Chunk error: {0}")]
47    ChunkError(String),
48
49    /// Reference error: invalid reference in the file
50    #[error("Reference error: {0}")]
51    ReferenceError(String),
52
53    /// Internal error: something went wrong in the parser logic
54    #[error("Internal error: {0}")]
55    InternalError(String),
56}
57
58/// Result type using M2Error
59pub type Result<T> = std::result::Result<T, M2Error>;
60
61impl From<M2Error> for WowDataError {
62    fn from(value: M2Error) -> Self {
63        WowDataError::GenericError(format!("M2Error: {}", value))
64    }
65}