pub enum ParseError {
Show 17 variants
UnexpectedChar(char, usize),
UnexpectedEof(usize),
InvalidNumber(usize),
InvalidEscape(usize),
InvalidUnicode(usize),
UnterminatedString(usize),
TrailingComma(usize),
Expected {
expected: String,
found: String,
position: usize,
},
DepthLimitExceeded(usize),
Custom(String),
WithContext {
message: String,
source: Box<Error>,
},
RepairFailed(String),
BracketMismatch(usize, char, char),
UnbalancedBrackets(usize, usize),
MaxRepairsExceeded(usize),
InvalidUtf8(usize),
InvalidChunk(String),
}Expand description
Error types that can occur during vexy_json parsing.
Each error variant contains positional information to help users locate and fix parsing issues in their input. The error types are designed to provide clear, actionable feedback.
Variants§
UnexpectedChar(char, usize)
Unexpected character encountered during parsing. Contains the character and its position in the input.
UnexpectedEof(usize)
Unexpected end of input while parsing. Contains the position where more input was expected.
InvalidNumber(usize)
Invalid number format encountered. Contains the position where the invalid number starts.
InvalidEscape(usize)
Invalid escape sequence in string. Contains the position of the invalid escape.
InvalidUnicode(usize)
Invalid unicode escape sequence. Contains the position of the invalid unicode escape.
UnterminatedString(usize)
String literal was not properly terminated. Contains the position where the string started.
TrailingComma(usize)
Trailing comma found when not allowed by parser options. Contains the position of the trailing comma.
Expected
Expected a specific token or value but found something else. This is the most flexible error type for parser expectations.
Fields
DepthLimitExceeded(usize)
Maximum recursion depth exceeded while parsing nested structures. Contains the position where the limit was exceeded.
Custom(String)
Custom error with a descriptive message. Used for configuration errors or other non-positional issues.
WithContext
An error that wraps another error, adding context.
RepairFailed(String)
JSON repair failed with the given error message.
BracketMismatch(usize, char, char)
Bracket mismatch detected during parsing.
UnbalancedBrackets(usize, usize)
Unbalanced brackets detected.
MaxRepairsExceeded(usize)
Maximum repair attempts exceeded.
InvalidUtf8(usize)
Invalid UTF-8 sequence encountered.
InvalidChunk(String)
Invalid chunk detected during parallel processing.
Implementations§
Source§impl Error
impl Error
Sourcepub fn code(&self) -> ErrorCode
pub fn code(&self) -> ErrorCode
Returns the error code for this error.
Error codes provide a structured way to identify and categorize different types of parsing errors programmatically.
Sourcepub fn position(&self) -> Option<usize>
pub fn position(&self) -> Option<usize>
Returns the position in the input where the error occurred, if available.
Most parsing errors have associated position information to help users locate the problematic input. Custom errors may not have position information and will return None.
Sourcepub fn span(&self) -> Option<Span>
pub fn span(&self) -> Option<Span>
Returns a span covering the error location, if available.
This provides more precise location information than just a position, including the range of characters that caused the error.
Sourcepub fn suggestions(&self) -> Vec<&'static str>
pub fn suggestions(&self) -> Vec<&'static str>
Returns suggestions for fixing this error.
Provides context-aware suggestions based on the error type and the specific situation that caused the error.
Sourcepub fn diagnostic(&self) -> String
pub fn diagnostic(&self) -> String
Returns a detailed diagnostic message including error code and suggestions.
This provides a comprehensive error report that includes the original
error message, error code, and actionable suggestions for fixing the issue.
For colored output, use diagnostic_colored or diagnostic_with_formatter.
Sourcepub fn diagnostic_with_formatter(&self, formatter: &TerminalFormatter) -> String
pub fn diagnostic_with_formatter(&self, formatter: &TerminalFormatter) -> String
Returns a detailed diagnostic message with colored terminal formatting.
This method provides the same comprehensive error report as diagnostic()
but uses colored output when the terminal supports it. Colors enhance
readability by highlighting error codes, messages, and suggestions.
Sourcepub fn diagnostic_colored(&self) -> String
pub fn diagnostic_colored(&self) -> String
Returns a detailed diagnostic message with colored output if terminal supports it.
This is a convenience method that automatically detects terminal capabilities and uses colored output when available, falling back to plain text otherwise.
Sourcepub fn diagnostic_plain(&self) -> String
pub fn diagnostic_plain(&self) -> String
Returns a detailed diagnostic message with plain text output (no colors).
This is a convenience method for when you specifically want plain text output regardless of terminal capabilities.
Sourcepub fn with_context<S>(self, message: S) -> Error
pub fn with_context<S>(self, message: S) -> Error
Creates a new error with additional context.
This allows wrapping an existing error with additional information while preserving the original error details.
Sourcepub fn with_parsing_context<S>(self, context: S, _span: Span) -> Error
pub fn with_parsing_context<S>(self, context: S, _span: Span) -> Error
Creates a new error with a custom context message and span.
This is useful when you need to provide additional context about what was being parsed when the error occurred.
Sourcepub fn is_string_error(&self) -> bool
pub fn is_string_error(&self) -> bool
Checks if this error is related to string parsing.
Useful for error categorization and specialized error handling.
Sourcepub fn is_number_error(&self) -> bool
pub fn is_number_error(&self) -> bool
Checks if this error is related to number parsing.
Useful for error categorization and specialized error handling.
Sourcepub fn is_structural_error(&self) -> bool
pub fn is_structural_error(&self) -> bool
Checks if this error is a structural parsing error.
Structural errors include bracket mismatches, unexpected tokens, etc.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl ErrorUtils for Error
impl ErrorUtils for Error
Source§fn position(&self) -> Option<usize>
fn position(&self) -> Option<usize>
Source§fn is_string_error(&self) -> bool
fn is_string_error(&self) -> bool
Source§fn is_number_error(&self) -> bool
fn is_number_error(&self) -> bool
Source§fn is_structural_error(&self) -> bool
fn is_structural_error(&self) -> bool
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more