1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/// Represnts all the possible reasons parsing json may could fail
#[derive(Debug, PartialEq, Eq)]
pub enum Reason {
    /// A token that looked like a boolean was in fact not one
    ExpectedBool,
    /// A token that looked like the null was not the null value
    ExpectedNull,
    /// Failed to parse what looked like a number
    ExpectedNumber,
    /// Encountered an invalid unicode/utf8 sequence while parsing a string
    InvalidUtf8,
/// Ran out of input before we finished parsing
    UnexpectedEof,
    /// Unexpected control character in string
    UnexpectedCtrlChar,
    /// Unexpected escape code in string
    UnexpectedEscapeCode,
    /// A character was not recognized as being part of a valid json construct
    UnexpectedChar,
}

/// Bundles the reason for a json parsing error with the position at which parsing failed
#[derive(Debug, thiserror::Error)]
#[error("Malformed json string. {0:?} at byte {1}")]
pub struct ParserErr(pub Reason, pub usize);