Skip to content

Commit

Permalink
Improve error classification triage
Browse files Browse the repository at this point in the history
(Or, more honestly, be less lazy!)
  • Loading branch information
Martin Bartlett committed Oct 28, 2024
1 parent 2523a50 commit 7ff68bb
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,42 @@ impl Error {
matches!(self.error, ErrorType::Eof)
}

/// Indicates if the error that occurred was due to a deserializer error
/// Indicates if the error that occurred was due to a data shape error
#[must_use]
pub fn is_data(&self) -> bool {
matches!(self.error, ErrorType::Parser | ErrorType::Serde(_))
// Lazy? maybe but if it aint something else...
!(self.is_syntax() || self.is_eof() || self.is_io())
}

/// Indicates if the error that occurred was due an input syntax error
/// Indicates if the error that occurred was due a JSON syntax error
#[must_use]
pub fn is_syntax(&self) -> bool {
// Lazy? maybe but if it aint something else...
!(self.is_data() || self.is_eof() || self.is_io())
matches!(self.error,
ErrorType::InputTooLarge |
ErrorType::BadKeyType |
ErrorType::ExpectedArrayComma |
ErrorType::ExpectedObjectColon |
ErrorType::ExpectedMapComma |
ErrorType::ExpectedMapEnd |
ErrorType::InvalidEscape |
ErrorType::InvalidExponent |
ErrorType::InvalidNumber |
ErrorType::InvalidUtf8 |
ErrorType::InvalidUnicodeEscape |
ErrorType::InvalidUnicodeCodepoint |
ErrorType::KeyMustBeAString |
ErrorType::NoStructure |
ErrorType::Parser |
ErrorType::Syntax |
ErrorType::TrailingData |
ErrorType::UnexpectedCharacter |
ErrorType::UnterminatedString |
ErrorType::ExpectedArrayContent |
ErrorType::ExpectedObjectContent |
ErrorType::ExpectedObjectKey |
ErrorType::Overflow |
ErrorType::SimdUnsupported)
}
}
impl std::error::Error for Error {}
Expand Down

0 comments on commit 7ff68bb

Please sign in to comment.