wow_m2/
error.rs

1use std::io;
2use thiserror::Error;
3
4use crate::anim::AnimFormat;
5
6/// Error types for M2 model parsing and processing
7#[derive(Error, Debug)]
8pub enum M2Error {
9    /// I/O Error during reading or writing
10    #[error("I/O error: {0}")]
11    Io(#[from] io::Error),
12
13    /// Invalid magic number in the file header
14    #[error("Invalid magic number: expected '{expected}', got '{actual}'")]
15    InvalidMagic { expected: String, actual: String },
16
17    /// Unsupported file version
18    #[error("Unsupported version: {0}")]
19    UnsupportedVersion(String),
20
21    /// Error during parsing
22    #[error("Parse error: {0}")]
23    ParseError(String),
24
25    /// Error during validation
26    #[error("Validation error: {0}")]
27    ValidationError(String),
28
29    /// Error during version conversion
30    #[error("Conversion error: cannot convert from version {from} to {to}: {reason}")]
31    ConversionError { from: u32, to: u32, reason: String },
32
33    /// Chunk error: missing expected chunk or invalid chunk
34    #[error("Chunk error: {0}")]
35    ChunkError(String),
36
37    /// Reference error: invalid reference in the file
38    #[error("Reference error: {0}")]
39    ReferenceError(String),
40
41    /// Internal error: something went wrong in the parser logic
42    #[error("Internal error: {0}")]
43    InternalError(String),
44
45    /// ANIM format detection failed
46    #[error("ANIM format detection failed: {0}")]
47    AnimFormatError(String),
48
49    /// Legacy ANIM parsing error
50    #[error("Legacy ANIM parsing error: {0}")]
51    LegacyAnimError(String),
52
53    /// ANIM format conversion error
54    #[error("ANIM format conversion error: from {from:?} to {to:?}: {reason}")]
55    AnimConversionError {
56        from: AnimFormat,
57        to: AnimFormat,
58        reason: String,
59    },
60
61    /// Invalid magic bytes in chunked format
62    #[error("Invalid magic bytes: {0:?}")]
63    InvalidMagicBytes([u8; 4]),
64
65    /// Missing required MD21 chunk
66    #[error("Missing required MD21 chunk")]
67    MissingMD21Chunk,
68
69    /// Malformed chunk header
70    #[error("Malformed chunk header")]
71    MalformedChunk,
72
73    /// Unknown FileDataID
74    #[error("Unknown FileDataID: {0}")]
75    UnknownFileDataId(u32),
76
77    /// Failed to resolve external file
78    #[error("Failed to resolve external file: {0}")]
79    ExternalFileError(String),
80}
81
82/// Result type using M2Error
83pub type Result<T> = std::result::Result<T, M2Error>;