serde_hkx/errors/ser.rs
1//! Serialize error
2use crate::lib::*;
3use havok_types::Pointer;
4
5/// Serialize error
6#[derive(Debug, snafu::Snafu)]
7#[snafu(visibility(pub))]
8pub enum Error {
9 /// {msg}
10 Message {
11 /// Error message
12 msg: String,
13 },
14
15 /// Only 0 (big) or 1 (little) can be specified for the header endian. But got {invalid}
16 InvalidEndian {
17 invalid: u8,
18 /// error location
19 #[snafu(implicit)]
20 location: snafu::Location,
21 },
22
23 /// The only supported pointer sizes are 4 and 8. But got {invalid}
24 UnsupportedPtrSize {
25 invalid: u8,
26 /// error location
27 #[snafu(implicit)]
28 location: snafu::Location,
29 },
30
31 /// Relative position cannot be obtained because abs is larger than {position}.
32 /// This indicates that the value of `absolute_data_offset` in the header is wrong.
33 OverflowSubtractAbs { position: u32, abs_data_offset: u32 },
34
35 /// Missing global fixup class: {ptr}
36 MissingGlobalFixupClass {
37 /// missing global fixup class ptr(e.g. #0050)
38 ptr: Pointer,
39 /// error location
40 #[snafu(implicit)]
41 location: snafu::Location,
42 },
43
44 /// The constructor class for virtual_fixup did not exist in the class
45 /// The constructor class for virtual_fixup did not exist in the class
46 /// in the `__classnames__` section written.: {class_name}
47 MissingClassInClassnamesSection {
48 class_name: &'static str,
49 /// error location
50 #[snafu(implicit)]
51 location: snafu::Location,
52 },
53
54 /// Not found where to write ptr. This could be an incorrect value inside hkx or a mistake by the library implementor.
55 NotFoundPointedPosition,
56
57 /// Invalid utf8 error
58 #[snafu(transparent)]
59 Utf8Error {
60 /// Invalid utf8 error
61 source: std::str::Utf8Error,
62 /// error location
63 #[snafu(implicit)]
64 location: snafu::Location,
65 },
66
67 /// Contain null bytes in a string error
68 #[snafu(transparent)]
69 NulError {
70 /// Contain null bytes in a string error
71 source: std::ffi::NulError,
72 /// error location
73 #[snafu(implicit)]
74 location: snafu::Location,
75 },
76
77 /// std io error.
78 #[snafu(transparent)]
79 IoError {
80 /// I/O Error
81 source: std::io::Error,
82 /// error location
83 #[snafu(implicit)]
84 location: snafu::Location,
85 },
86
87 /// The state machine in behavior is topologically sorted circularly referenced.
88 #[snafu(display(
89 "The state machine in behavior is topologically sorted circularly referenced."
90 ))]
91 UnexpectedCyclicSort {
92 #[snafu(implicit)]
93 location: snafu::Location,
94 },
95}
96
97impl havok_serde::ser::Error for Error {
98 fn custom<T>(msg: T) -> Self
99 where
100 T: Display,
101 {
102 Self::Message {
103 msg: msg.to_string(),
104 }
105 }
106}
107
108/// Wrapper on [`core::result::Result`] for Serializer.
109pub type Result<T, E = Error> = core::result::Result<T, E>;