1use std::io;
2use thiserror::Error;
3
4use crate::anim::AnimFormat;
5
6#[derive(Error, Debug)]
8pub enum M2Error {
9 #[error("I/O error: {0}")]
11 Io(#[from] io::Error),
12
13 #[error("Invalid magic number: expected '{expected}', got '{actual}'")]
15 InvalidMagic { expected: String, actual: String },
16
17 #[error("Unsupported version: {0}")]
19 UnsupportedVersion(String),
20
21 #[error("Parse error: {0}")]
23 ParseError(String),
24
25 #[error("Validation error: {0}")]
27 ValidationError(String),
28
29 #[error("Conversion error: cannot convert from version {from} to {to}: {reason}")]
31 ConversionError { from: u32, to: u32, reason: String },
32
33 #[error("Chunk error: {0}")]
35 ChunkError(String),
36
37 #[error("Reference error: {0}")]
39 ReferenceError(String),
40
41 #[error("Internal error: {0}")]
43 InternalError(String),
44
45 #[error("ANIM format detection failed: {0}")]
47 AnimFormatError(String),
48
49 #[error("Legacy ANIM parsing error: {0}")]
51 LegacyAnimError(String),
52
53 #[error("ANIM format conversion error: from {from:?} to {to:?}: {reason}")]
55 AnimConversionError {
56 from: AnimFormat,
57 to: AnimFormat,
58 reason: String,
59 },
60
61 #[error("Invalid magic bytes: {0:?}")]
63 InvalidMagicBytes([u8; 4]),
64
65 #[error("Missing required MD21 chunk")]
67 MissingMD21Chunk,
68
69 #[error("Malformed chunk header")]
71 MalformedChunk,
72
73 #[error("Unknown FileDataID: {0}")]
75 UnknownFileDataId(u32),
76
77 #[error("Failed to resolve external file: {0}")]
79 ExternalFileError(String),
80}
81
82pub type Result<T> = std::result::Result<T, M2Error>;