#[non_exhaustive]pub enum JsonValidatedDecodeError<E, R = JsonResource, Q = usize>where
Q: ResourceQuantity,{
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.
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
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: EError 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.
ExactSafeInteger
Exact-safe-integer conversion failed.
Fields
source: JsonNumberTokenErrorExact conversion failure category.
Limit
An additional validated decode limit was exceeded.
Trait Implementations§
Source§impl<E, R, Q> Debug for JsonValidatedDecodeError<E, R, Q>where
R: Debug,
Q: ResourceQuantity,
impl<E, R, Q> Debug for JsonValidatedDecodeError<E, R, Q>where
R: Debug,
Q: ResourceQuantity,
Source§impl<E, R, Q> Display for JsonValidatedDecodeError<E, R, Q>where
R: Debug,
Q: ResourceQuantity,
impl<E, R, Q> Display for JsonValidatedDecodeError<E, R, Q>where
R: Debug,
Q: ResourceQuantity,
Source§impl<E, R, Q> Error for JsonValidatedDecodeError<E, R, Q>
impl<E, R, Q> Error for JsonValidatedDecodeError<E, R, Q>
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()