Skip to main content

JsonValueEncodeError

Enum JsonValueEncodeError 

Source
#[non_exhaustive]
pub enum JsonValueEncodeError<R, Q>{ Budget(MeasuredBudgetError<R, Q>), Serialization(JsonSerializationError), PrivateTextLimitExceeded { maximum: usize, }, }
Expand description

Failure while projecting a Serde value into a budgeted JSON tree.

The error distinguishes resource budget rejection, strict JSON serialization failure, and private text payloads that exceed their configured limit. Because this type is non-exhaustive, matches outside this crate must include a fallback arm. After any failure, discard the entire caller-owned resource transaction; do not treat its partial measurements as a successful projection.

None from a serialization query does not indicate success. It means that the error is not a serialization failure.

§Type Parameters

  • R is the resource identifier type used by the budget.
  • Q is the resource quantity type and must implement ResourceQuantity.

§Examples

use qubit_budget::json::JsonResource;
use qubit_budget::json::JsonValueBudget;
use qubit_budget::json::JsonValueLimits;
use qubit_json::value::JsonValueEncodeError;
use qubit_json::value::JsonValueEncoder;
use serde_json::value::RawValue;

let limits = JsonValueLimits::<JsonResource, usize>::new();
let mut budget = JsonValueBudget::new(limits);
let mut transaction = budget.transaction();
let raw = RawValue::from_string("null".to_owned()).unwrap();
let error = JsonValueEncoder::new()
    .encode_in_transaction_with_private_text_limit(&raw, &mut transaction, 0)
    .unwrap_err();
let classification = match &error {
    JsonValueEncodeError::Budget(_) => "budget",
    JsonValueEncodeError::Serialization(_) => "serialization",
    JsonValueEncodeError::PrivateTextLimitExceeded { maximum } => {
        assert_eq!(*maximum, 0);
        "private text limit"
    }
    _ => "other",
};
assert_eq!(classification, "private text limit");
assert!(error.serialization_error().is_none());
assert!(error.kind().is_none());
assert!(error.category().is_none());
drop(transaction);

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.
§

Budget(MeasuredBudgetError<R, Q>)

The caller’s resource transaction rejected a value.

Tuple Fields

§0: MeasuredBudgetError<R, Q>

The measured resource or quantity that caused admission to fail.

§

Serialization(JsonSerializationError)

The Serde value could not be represented as strict JSON.

Tuple Fields

§0: JsonSerializationError

The privacy-safe strict JSON serialization failure.

§

PrivateTextLimitExceeded

A private RawValue or Number payload exceeded its configured UTF-8 text limit.

Fields

§maximum: usize

Maximum UTF-8 byte length allowed for one private text payload.

Implementations§

Source§

impl<R, Q> JsonValueEncodeError<R, Q>

Source

pub const fn serialization_error(&self) -> Option<&JsonSerializationError>

Returns the underlying serialization error when Serde projection failed.

§Returns

Returns Some for Self::Serialization. Returns None for Self::Budget and Self::PrivateTextLimitExceeded; None means the failure is not a serialization error, not that projection succeeded.

Source

pub const fn kind(&self) -> Option<JsonSerializationErrorKind>

Returns the stable serialization failure kind, if applicable.

§Returns

Returns Some for Self::Serialization. Returns None for Self::Budget and Self::PrivateTextLimitExceeded; None means the failure has no serialization kind, not that projection succeeded.

Source

pub const fn category(&self) -> Option<JsonSerializationErrorCategory>

Returns the broad serialization category, if applicable.

§Returns

Returns Some for Self::Serialization. Returns None for Self::Budget and Self::PrivateTextLimitExceeded; None means the failure has no serialization category, not that projection succeeded.

Source

pub const fn is_number_error(&self) -> bool

Reports whether the serialization failure concerns a JSON number.

Source

pub const fn is_map_key_error(&self) -> bool

Reports whether the serialization failure concerns an object key.

Source

pub const fn is_raw_value_error(&self) -> bool

Reports whether the serialization failure concerns a raw JSON value.

Source

pub const fn is_serializer_contract_error(&self) -> bool

Reports whether Serde violated a serializer protocol contract.

Source

pub const fn integer_signedness(&self) -> Option<JsonIntegerSignedness>

Returns the rejected integer signedness, if applicable.

Source

pub const fn map_key_kind(&self) -> Option<JsonMapKeyKind>

Returns the unsupported map-key category, if applicable.

Source

pub const fn collection_kind(&self) -> Option<JsonCollectionKind>

Returns the collection whose length overflowed, if applicable.

Source

pub const fn serializer_state_error(&self) -> Option<JsonSerializerStateError>

Returns the serializer protocol state failure, if applicable.

Trait Implementations§

Source§

impl<R: Debug, Q> Debug for JsonValueEncodeError<R, Q>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R, Q> Display for JsonValueEncodeError<R, Q>

Source§

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

Formats the failure without exposing private payload contents.

§Parameters
  • f is the formatter that receives the privacy-safe failure message.
Source§

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

Source§

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

Returns the underlying budget or serialization cause, when present.

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<R, Q> Forget for JsonValueEncodeError<R, Q>

§

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

§

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

§

impl<R, Q> RefUnwindSafe for JsonValueEncodeError<R, Q>

§

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

§

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

§

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

§

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

§

impl<R, Q> UnwindSafe for JsonValueEncodeError<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.