serde_hkx/errors/
de.rs

1//! Deserialize error
2use crate::lib::*;
3
4/// Deserialize error
5#[derive(Debug, PartialEq, snafu::Snafu)]
6pub enum Error {
7    /// {msg}
8    Message {
9        /// Error message
10        msg: String,
11    },
12
13    /// The number of required constructors in C++ is insufficient. actual: {actual}, expected: {expected}
14    LackOfConstructors { actual: usize, expected: usize },
15
16    /// The data position pointed to by the pointer of the read position ({key}) is not found in local_fixups.
17    NotFoundDataLocalFixupsValue { key: u32 },
18
19    /// Could not find the {index}th corresponding class: {start_offset}
20    NotFoundClass { index: usize, start_offset: u32 },
21
22    /// Class Ptr is None.
23    NotFoundClassPtr,
24
25    /// Incomplete parsing binary.
26    TrailingBytes,
27
28    /// Still need to parse the syntax but the string provided is not enough.
29    Eof,
30
31    /// Incomplete parsing XML. Remain: {remain}
32    TrailingCharacters { remain: String },
33
34    /// Expected class {expected}, but got {actual}.
35    MismatchClassName {
36        actual: &'static str,
37        expected: String,
38    },
39
40    /// Parser combinator Error
41    #[snafu(display("{err}"))]
42    ContextError {
43        err: winnow::error::ErrMode<winnow::error::ContextError>,
44    },
45
46    /// Human readable XML parsing error
47    #[snafu(transparent)]
48    ReadableError {
49        source: super::readable::ReadableError,
50    },
51}
52
53impl havok_serde::de::Error for Error {
54    fn custom<T>(msg: T) -> Self
55    where
56        T: Display,
57    {
58        Self::Message {
59            msg: msg.to_string(),
60        }
61    }
62}
63
64/// Wrapper on [`core::result::Result`] for Deserializer.
65pub type Result<T, E = Error> = core::result::Result<T, E>;