Skip to main content

JsonDecodeErrorSource

Enum JsonDecodeErrorSource 

Source
pub enum JsonDecodeErrorSource<R, Q = usize>
where Q: Copy + Debug,
{ Read { raw_input_bytes: usize, kind: ErrorKind, source: Option<Arc<Error>>, }, Budget { stage: JsonDecodeStage, raw_input_bytes: usize, normalized_input_bytes: Option<usize>, source: MeasuredBudgetError<R, Q>, }, EmptyInput { stage: JsonDecodeStage, raw_input_bytes: usize, normalized_input_bytes: Option<usize>, }, InvalidUtf8 { raw_input_bytes: usize, valid_up_to: usize, error_len: Option<usize>, source: Option<Utf8Error>, }, InvalidJson { raw_input_bytes: usize, normalized_input_bytes: Option<usize>, syntax: JsonSyntaxError, source: Option<Arc<dyn Error + Send + Sync>>, }, UnexpectedTopLevel { raw_input_bytes: usize, normalized_input_bytes: Option<usize>, expected: JsonRootKind, actual: JsonRootKind, }, Deserialize { raw_input_bytes: usize, normalized_input_bytes: Option<usize>, line: usize, column: usize, source: Option<Arc<dyn Error + Send + Sync>>, }, }
Expand description

An owned semantic source extracted from a JSON decoding failure.

This enum contains the owned operation-level source for one failure. It lets downstream adapters move that source into their own models with one exhaustive match, without pairing super::JsonDecodeError::kind with fallible source accessors. A materialization reason is stored separately: read it with super::JsonDecodeError::materialization_error_reason before consuming the error with super::JsonDecodeError::into_source. Parser and Serde sources remain present only when decoding used super::DiagnosticPolicy::Detailed.

§Type Parameters

  • R - Resource identity attached to budget failures.
  • Q - Quantity representation attached to budget failures.

§Examples

use qubit_json::decode::{JsonDecodeErrorSource, JsonDecoder};

let mut decoder = JsonDecoder::unlimited();
let error = decoder.validate_str("{").expect_err("invalid JSON must fail");
match error.into_source() {
    JsonDecodeErrorSource::InvalidJson { syntax, .. } => {
        assert_eq!(syntax.offset(), 1);
    }
    source => panic!("unexpected decoding source: {source:?}"),
}

Variants§

§

Read

Reading input failed before text decoding began.

Fields

§raw_input_bytes: usize

Number of bytes observed as read before the failure; this is not necessarily the amount charged by every input path.

§kind: ErrorKind

Stable standard I/O failure category.

§source: Option<Arc<Error>>

Original error retained only under detailed diagnostics.

§

Budget

A resource measurement was rejected.

Fields

§stage: JsonDecodeStage

Semantic stage where the measurement was rejected.

§raw_input_bytes: usize

Original input length observed at the decoding boundary; not necessarily the amount charged to an input-byte budget.

§normalized_input_bytes: Option<usize>

Predicted normalized target length when available; it does not prove that normalized text was allocated or rewritten.

§source: MeasuredBudgetError<R, Q>

Complete measured-budget failure.

§

EmptyInput

Input was empty at a public boundary.

Fields

§stage: JsonDecodeStage

Semantic stage where emptiness was detected.

§raw_input_bytes: usize

Original input length observed at the decoding boundary.

§normalized_input_bytes: Option<usize>

Predicted normalized target length when available; it does not prove that normalized text was produced.

§

InvalidUtf8

Raw bytes were not valid UTF-8.

Fields

§raw_input_bytes: usize

Original input length observed at the decoding boundary.

§valid_up_to: usize

Valid prefix length reported by UTF-8 validation.

§error_len: Option<usize>

Invalid sequence length when known.

§source: Option<Utf8Error>

Detailed source retained only under detailed diagnostics.

§

InvalidJson

Text was not one valid JSON document.

Fields

§raw_input_bytes: usize

Original input length observed at the decoding boundary.

§normalized_input_bytes: Option<usize>

Predicted normalized target length when available; it does not prove that normalized text was allocated or rewritten.

§syntax: JsonSyntaxError

Stable scanner reason and source coordinates.

§source: Option<Arc<dyn Error + Send + Sync>>

Detailed parser source retained only under detailed diagnostics.

§

UnexpectedTopLevel

A valid document had an unexpected top-level kind.

Fields

§raw_input_bytes: usize

Original input length observed at the decoding boundary.

§normalized_input_bytes: Option<usize>

Predicted normalized target length when available; it does not prove that normalized text was produced.

§expected: JsonRootKind

Required top-level kind.

§actual: JsonRootKind

Observed top-level kind.

§

Deserialize

A valid admitted document could not materialize the target type.

Fields

§raw_input_bytes: usize

Original input length observed at the decoding boundary.

§normalized_input_bytes: Option<usize>

Predicted normalized target length when available; it does not prove that normalized text was produced.

§line: usize

One-based Serde line, or zero when unavailable.

§column: usize

One-based Serde column, or zero when unavailable.

§source: Option<Arc<dyn Error + Send + Sync>>

Detailed source retained only under detailed diagnostics.

Trait Implementations§

Source§

impl<R: Clone, Q> Clone for JsonDecodeErrorSource<R, Q>
where Q: Copy + Debug + Clone,

Source§

fn clone(&self) -> Self

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<R: Debug, Q> Debug for JsonDecodeErrorSource<R, Q>
where Q: Copy + Debug + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, Q = usize> !RefUnwindSafe for JsonDecodeErrorSource<R, Q>

§

impl<R, Q = usize> !UnwindSafe for JsonDecodeErrorSource<R, Q>

§

impl<R, Q> Forget for JsonDecodeErrorSource<R, Q>

§

impl<R, Q> Freeze for JsonDecodeErrorSource<R, Q>

§

impl<R, Q> Move for JsonDecodeErrorSource<R, Q>

§

impl<R, Q> Send for JsonDecodeErrorSource<R, Q>

§

impl<R, Q> Sync for JsonDecodeErrorSource<R, Q>

§

impl<R, Q> Unpin for JsonDecodeErrorSource<R, Q>

§

impl<R, Q> UnsafeUnpin for JsonDecodeErrorSource<R, Q>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.