pub enum JsonDecodeErrorSource<R, Q = usize>{
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
Budget
A resource measurement was rejected.
Fields
stage: JsonDecodeStageSemantic stage where the measurement was rejected.
raw_input_bytes: usizeOriginal 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: JsonDecodeStageSemantic stage where emptiness was detected.
InvalidUtf8
Raw bytes were not valid UTF-8.
Fields
InvalidJson
Text was not one valid JSON document.
Fields
normalized_input_bytes: Option<usize>Predicted normalized target length when available; it does not prove that normalized text was allocated or rewritten.
syntax: JsonSyntaxErrorStable scanner reason and source coordinates.
UnexpectedTopLevel
A valid document had an unexpected top-level kind.
Fields
normalized_input_bytes: Option<usize>Predicted normalized target length when available; it does not prove that normalized text was produced.
expected: JsonRootKindRequired top-level kind.
actual: JsonRootKindObserved top-level kind.
Deserialize
A valid admitted document could not materialize the target type.