me3_coalesced_parser/
error.rs1use std::{error::Error, fmt::Display};
2
3#[derive(Debug)]
4pub enum DecodeError {
5 UnexpectedEof {
8 cursor: usize,
10 wanted: usize,
12 remaining: usize,
14 },
15
16 UnknownFileMagic,
17 StringTableHashMismatch,
18 StringTableSizeMismatch,
19 InvalidNameOffset,
20 UnknownValueType,
21 MalformedDecompressionNodes,
22}
23
24pub type DecodeResult<T> = Result<T, DecodeError>;
26
27impl Error for DecodeError {}
29
30impl Display for DecodeError {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 DecodeError::UnexpectedEof {
35 cursor,
36 wanted,
37 remaining,
38 } => {
39 write!(
40 f,
41 "Unexpected end of file (cursor: {}, wanted: {}, remaining: {})",
42 cursor, wanted, remaining
43 )
44 }
45 DecodeError::UnknownFileMagic => f.write_str("Unexpected file magic bytes"),
46 DecodeError::StringTableHashMismatch => f.write_str("String table hash didn't match"),
47 DecodeError::StringTableSizeMismatch => f.write_str("String table size didn't match"),
48 DecodeError::InvalidNameOffset => f.write_str("Invalid name offset"),
49 DecodeError::UnknownValueType => f.write_str("Unknown value type"),
50 DecodeError::MalformedDecompressionNodes => {
51 f.write_str("Decompression nodes are malformed")
52 }
53 }
54 }
55}