Skip to main content

JsonValidatedDecodeError

Enum JsonValidatedDecodeError 

Source
#[non_exhaustive]
pub enum JsonValidatedDecodeError<E, R = JsonResource, Q = usize>{ Decode { error: JsonDecodeError<R, Q>, context: Option<JsonDecodeContext>, }, Policy { source: E, offset: usize, }, ExactSafeInteger { source: JsonNumberTokenError, offset: usize, }, Limit { limit: JsonValidatedLimit, maximum: usize, observed: usize, offset: usize, }, }
Expand description

A validated decoding failure with source offset and privacy-safe outer formatting.

The Policy variant preserves the caller’s error unchanged. Its contents are omitted from this error’s Display and Debug output, but are available through Error::source. This caller-provided source is outside super::DiagnosticPolicy’s redaction boundary; callers must choose safe policy error contents and logging behavior themselves.

§Type Parameters

  • E - Error returned by the caller’s number policy; it must implement Error when this value is used as an error source.
  • R - Resource identity carried by the underlying decode error; defaults to JsonResource, and must implement fmt::Debug for formatting.
  • Q - Resource quantity accepted by ResourceQuantity, which limits quantities to supported unsigned integer types; defaults to usize.

§Examples

use qubit_json::decode::{
    DiagnosticPolicy, JsonDecoder, JsonNumberPolicy,
    JsonValidatedDecodeError, JsonValidatedDecodeOptions,
};
use std::error::Error;

let options = JsonValidatedDecodeOptions::builder().build();
let error = JsonDecoder::unlimited()
    .with_diagnostic_policy(DiagnosticPolicy::Redacted)
    .decode_unique_validated_str("1", &options, |_, token| {
        Err::<JsonNumberPolicy, _>(std::io::Error::other(format!(
            "policy-sensitive-marker:{}", token.raw(),
        )))
    })
    .unwrap_err();
let sentinel = "policy-sensitive-marker";
assert!(!error.to_string().contains(sentinel));
assert!(!format!("{error:?}").contains(sentinel));
let source = Error::source(&error).expect("caller policy error is preserved");
assert!(source.to_string().contains(sentinel));
assert!(matches!(error, JsonValidatedDecodeError::Policy { .. }));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Decode

A decoder, syntax, budget, or input failure.

Fields

§error: JsonDecodeError<R, Q>

Structured decoding failure.

§context: Option<JsonDecodeContext>

Grammar location associated with the failure, when known.

§

Policy

The caller’s number policy rejected a source token.

Fields

§source: E

Error returned by the caller’s policy, preserved as the source.

This value is not redacted by super::DiagnosticPolicy. Its formatting is omitted from the outer error’s Display and Debug, but it remains accessible through Error::source. The caller is responsible for keeping sensitive data out of this error and its logs.

§offset: usize

Byte offset of the rejected number token.

§

ExactSafeInteger

Exact-safe-integer conversion failed.

Fields

§source: JsonNumberTokenError

Exact conversion failure category.

§offset: usize

Byte offset of the number token.

§

Limit

An additional validated decode limit was exceeded.

Fields

§limit: JsonValidatedLimit

Limit that rejected the document.

§maximum: usize

Configured maximum.

§observed: usize

Value observed when the limit was checked.

§offset: usize

Byte offset associated with the rejected token.

Trait Implementations§

Source§

impl<E, R, Q> Debug for JsonValidatedDecodeError<E, R, Q>
where R: Debug, Q: ResourceQuantity,

Source§

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

Formats this error for debugging while omitting caller policy details.

The Policy variant’s source is intentionally excluded so its potentially sensitive contents do not appear in debug output.

§Parameters
  • f - Formatter that receives the safe debug representation.
§Returns

Returns Ok(()) after formatting, or the formatter’s error if writing fails.

Source§

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

Source§

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

Formats the failure category and safe location details for users.

Caller policy error contents are intentionally omitted from the formatted message.

§Parameters
  • f - Formatter that receives the failure category and location.
§Returns

Returns Ok(()) after formatting, or the formatter’s error if writing fails.

Source§

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

Source§

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

Returns the underlying decoding or policy error when one is available.

The caller’s policy error remains accessible as a source even though this type omits its contents from Display and Debug output.

§Returns

Returns the wrapped decoding or policy error for those variants, the exact-safe-integer conversion error for that variant, or None when the failure has no underlying error.

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

Auto Trait Implementations§

§

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

§

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

§

impl<E, R, Q> Forget for JsonValidatedDecodeError<E, R, Q>

§

impl<E, R, Q> Freeze for JsonValidatedDecodeError<E, R, Q>
where JsonDecodeError<R, Q>: Freeze, E: Freeze,

§

impl<E, R, Q> Move for JsonValidatedDecodeError<E, R, Q>

§

impl<E, R, Q> Send for JsonValidatedDecodeError<E, R, Q>
where JsonDecodeError<R, Q>: Send, E: Send,

§

impl<E, R, Q> Sync for JsonValidatedDecodeError<E, R, Q>
where JsonDecodeError<R, Q>: Sync, E: Sync,

§

impl<E, R, Q> Unpin for JsonValidatedDecodeError<E, R, Q>
where JsonDecodeError<R, Q>: Unpin, E: Unpin,

§

impl<E, R, Q> UnsafeUnpin for JsonValidatedDecodeError<E, 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> 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> 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.