Skip to main content

ParseError

Enum ParseError 

Source
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

§expected: String

Description of what was expected.

§found: String

Description of what was actually found.

§position: usize

Position in the input where the mismatch occurred.

§

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.

Fields

§message: String

A descriptive message for the context.

§source: Box<Error>

The source error.

§

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn with_context<S>(self, message: S) -> Error
where S: Into<String>,

Creates a new error with additional context.

This allows wrapping an existing error with additional information while preserving the original error details.

Source

pub fn with_parsing_context<S>(self, context: S, _span: Span) -> Error
where S: Into<String>,

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.

Source

pub fn is_string_error(&self) -> bool

Checks if this error is related to string parsing.

Useful for error categorization and specialized error handling.

Source

pub fn is_number_error(&self) -> bool

Checks if this error is related to number parsing.

Useful for error categorization and specialized error handling.

Source

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 Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl ErrorUtils for Error

Source§

fn position(&self) -> Option<usize>

Returns the position in the input where the error occurred, if available. Read more
Source§

fn is_string_error(&self) -> bool

Checks if this error is related to string parsing. Read more
Source§

fn is_number_error(&self) -> bool

Checks if this error is related to number parsing. Read more
Source§

fn is_structural_error(&self) -> bool

Checks if this error is a structural parsing error. Read more
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Error) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.