Skip to main content

JsonDecodeError

Struct JsonDecodeError 

Source
pub struct JsonDecodeError<R = JsonResource, Q = usize>
where Q: Copy + Debug,
{ /* private fields */ }
Expand description

Failure produced by either strict or normalizing JSON decoding.

Internal variants are private so callers branch through stable semantic accessors rather than depending on scanner, normalizer, or Serde details.

§Type Parameters

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

§Examples

use qubit_json::decode::{JsonDecodeError, JsonDecodeErrorKind, JsonDecoder};
use serde_json::Value;

let mut decoder = JsonDecoder::unlimited();
let error: JsonDecodeError = decoder
    .decode_str::<Value>("")
    .expect_err("empty input must be rejected");
assert_eq!(error.kind(), JsonDecodeErrorKind::InvalidJson);

Implementations§

Source§

impl<R, Q> JsonDecodeError<R, Q>
where Q: Copy + Debug,

Source

pub const fn kind(&self) -> JsonDecodeErrorKind

Returns the stable failure category.

§Returns

The category describing which kind of decode operation failed.

Source

pub const fn materialization_error_reason( &self, ) -> Option<JsonMaterializationErrorReason>

Returns the safe reason for a unique-key intermediate-tree failure.

Returns Some(reason) when unique-key tree construction failed because of a duplicate key or a defensive unrepresentable admitted number. The legacy depth-limit reason remains for source compatibility, but the shared builder has no fixed container cap and configured depth failures are reported as budget errors. Returns None for lexical, input, budget, and target-deserialization failures. The reason remains available under redacted diagnostics and contains no input-derived text. Read it before consuming the error with Self::into_source.

§Examples
use qubit_json::decode::{JsonDecoder, JsonMaterializationErrorReason};
use serde_json::Value;

let mut decoder = JsonDecoder::unlimited();
let error = decoder
    .decode_unique_str::<Value>(r#"{"id":1,"id":2}"#)
    .expect_err("duplicate keys must be rejected");
assert_eq!(
    error.materialization_error_reason(),
    Some(JsonMaterializationErrorReason::DuplicateKey),
);
Source

pub const fn stage(&self) -> JsonDecodeStage

Returns the semantic stage that produced the failure.

§Returns

The pipeline stage at which the failure was recorded.

Source

pub const fn diagnostic_policy(&self) -> DiagnosticPolicy

Returns the diagnostic policy applied while constructing this error.

§Returns

The policy that determines whether input-derived details are retained.

Source

pub const fn raw_input_bytes(&self) -> usize

Returns the raw input length observed at the decoding boundary.

For slice-based entry points, this is the complete input slice length, including when input admission rejects the slice before processing it. For decode_input, this is the length of the prefix read and retained before the error; a byte consumed only to probe past the input budget is excluded. The value therefore does not universally represent bytes charged to the budget or the session’s cumulative input usage.

§Returns

The raw input length observed for the input that caused this error.

Source

pub const fn normalized_input_bytes(&self) -> Option<usize>

Returns the predicted normalized text length when it is available.

A value may be present even when a budget rejected the input before normalized text was allocated or rewritten. This reports a target length, not proof that a normalized document was produced or charged.

§Returns

Some(length) when normalization determined a target length, or None when the failure occurred before that length was available.

Source

pub const fn read_error_kind(&self) -> Option<ErrorKind>

Returns the standard I/O error category for a read failure.

§Returns

Some(kind) for a read failure, or None for other failure kinds.

Source

pub fn read_error(&self) -> Option<&Error>

Returns the retained original I/O error for detailed read diagnostics.

§Returns

The original read error when detailed diagnostics retained it, or None when the error is not a read failure or its source was not retained.

Source

pub const fn line(&self) -> Option<usize>

Returns the one-based error line when available.

Invalid-JSON coordinates come from the lexical scanner. Deserialize coordinates preserve serde_json’s one-based line values, including unique-key materialization errors. For a deserialize error, a backend line of zero is reported as None.

§Returns

Some(line) for failures with source coordinates, otherwise None.

Source

pub const fn column(&self) -> Option<usize>

Returns the one-based error column when available.

Invalid-JSON columns count UTF-8 characters, while deserialize columns preserve serde_json’s byte-based column. Unique-key materialization columns count bytes before the offending token, with only LF starting a new line. For a deserialize error, a backend column of zero is reported as None.

§Returns

Some(column) for failures with source coordinates, otherwise None.

Source

pub const fn syntax_error(&self) -> Option<&JsonSyntaxError>

Returns the structured syntax failure for invalid JSON.

§Returns

A borrowed syntax error when parsing failed, otherwise None.

Source

pub const fn budget_error(&self) -> Option<&MeasuredBudgetError<R, Q>>

Returns the complete measured-budget failure when present.

§Returns

A borrowed budget error when resource accounting rejected the input, otherwise None.

Source

pub const fn utf8_valid_up_to(&self) -> Option<usize>

Returns the valid UTF-8 prefix length for invalid byte input.

§Returns

Some(bytes) for an invalid UTF-8 failure, or None for other failure kinds.

Source

pub const fn utf8_error_len(&self) -> Option<usize>

Returns the invalid UTF-8 sequence length when known.

§Returns

The length of the invalid sequence when the decoder can determine it, otherwise None.

Source

pub const fn expected_top_level(&self) -> Option<JsonRootKind>

Returns the expected top-level kind for a constrained decode failure.

§Returns

The required root kind when a constrained operation failed, otherwise None.

Source

pub const fn actual_top_level(&self) -> Option<JsonRootKind>

Returns the observed top-level kind for a constrained decode failure.

§Returns

The root kind observed in the valid document, otherwise None.

Source

pub fn into_source(self) -> JsonDecodeErrorSource<R, Q>

Consumes this error and returns its owned operation-level source.

The materialization reason returned by Self::materialization_error_reason is stored separately and is not included in the returned source. Read it before consuming this error. Input-derived third-party sources remain present only when the decoder used DiagnosticPolicy::Detailed.

§Returns

The owned budget, input, syntax, top-level, or deserialization source retained by this error. Any materialization reason is not returned.

§Examples
use qubit_json::decode::{
    JsonDecodeErrorSource, JsonDecoder, JsonMaterializationErrorReason,
};

let error = JsonDecoder::unlimited()
    .decode_value_str(r#"{"id":1,"id":2}"#)
    .expect_err("duplicate keys must be rejected");
let reason = error.materialization_error_reason();
let source = error.into_source();

assert_eq!(reason, Some(JsonMaterializationErrorReason::DuplicateKey));
assert!(matches!(source, JsonDecodeErrorSource::Deserialize { .. }));

Trait Implementations§

Source§

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

Source§

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

Formats structured diagnostics retained under the active policy.

§Parameters
  • formatter - Destination that receives the debug representation.
§Returns

Ok(()) after the structured diagnostic has been written.

§Errors

Returns the formatter error if writing the diagnostic fails.

Source§

impl<R, Q> Display for JsonDecodeError<R, Q>
where R: Debug, Q: ResourceQuantity,

Source§

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

Formats a privacy-safe or detailed message according to the policy.

§Parameters
  • formatter - Destination that receives the display message.
§Returns

Ok(()) after the policy-appropriate message has been written.

§Errors

Returns the formatter error if writing the message fails.

Source§

impl<R, Q> Error for JsonDecodeError<R, Q>
where R: Debug + 'static, Q: ResourceQuantity + 'static,

Source§

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

Returns budget sources unconditionally and input-derived sources only when detailed diagnostics retained them.

§Returns

The retained source error, or None when this failure has no source or input-derived diagnostics were redacted.

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

Source§

fn from(error: JsonDecodeError<R, Q>) -> Self

Wraps a regular decoding failure as a JCS decoding failure.

§Parameters
  • error - Regular decoding failure to wrap.
§Returns

A JCS error containing the supplied decoding failure.

Auto Trait Implementations§

§

impl<R = JsonResource, Q = usize> !RefUnwindSafe for JsonDecodeError<R, Q>

§

impl<R = JsonResource, Q = usize> !UnwindSafe for JsonDecodeError<R, Q>

§

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

§

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

§

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

§

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

§

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

§

impl<R, Q> UnsafeUnpin for JsonDecodeError<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> 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 = !

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.