1use std::{io, str::Utf8Error};
2
3#[derive(Debug)]
5pub enum Error {
6 Io(io::Error),
8 InvalidBoolValue(u8),
10 InvalidIntegerEncoding,
12 IntegerOverflow,
14 InvalidPath,
16 InvalidCharEncoding,
18 Utf8Error(Utf8Error),
20 Serialize(String),
22 Deserialize(String),
24 Conversion(String),
26}
27
28impl std::error::Error for Error {
29 #[inline]
30 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31 match self {
32 Error::Io(ref x) => Some(x),
33 Error::Utf8Error(ref x) => Some(x),
34 _ => None,
35 }
36 }
37}
38
39impl std::fmt::Display for Error {
40 #[inline]
41 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
42 match self {
43 Self::Io(e) => write!(f, "An IO error occured: {}", e),
44 Self::InvalidBoolValue(_) => {
45 write!(f, "Tried to deserialize a boolean value with an invalid byte value.")
46 }
47 Self::InvalidIntegerEncoding => {
48 write!(f, "Encountered invalid integer encoding.")
49 }
50 Self::IntegerOverflow => {
51 write!(f, "Encountered integer which doesn't fit the target integer type during deserialization.")
52 }
53 Self::InvalidPath => {
54 write!(f, "Path contained invalid UTF-8 characters.")
55 }
56 Self::InvalidCharEncoding => {
57 write!(f, "Invalid character encoding.")
58 }
59 Self::Utf8Error(x) => {
60 write!(f, "Invalid UTF-8 characters in string: {x}")
61 }
62 Self::Serialize(e) => write!(f, "A serialization error occured: {}", e),
63 Self::Deserialize(e) => write!(f, "A deserialization error occured: {}", e),
64 Self::Conversion(e) => write!(f, "A user generated conversion error occured: {}", e),
65 }
66 }
67}