Skip to main content

DeserializeError

Enum DeserializeError 

Source
#[non_exhaustive]
pub enum DeserializeError {
Show 67 variants Message { msg: String, location: Location, }, InvalidOptions { msg: String, location: Location, }, ExternalMessage { source: Box<ExternalMessageSource>, msg: String, code: Option<String>, params: Vec<(String, String)>, location: Location, }, Eof { location: Location, }, MultipleDocuments { hint: &'static str, location: Location, }, Unexpected { expected: &'static str, location: Location, }, MergeValueNotMapOrSeqOfMaps { location: Location, }, MergeKeyNotAllowed { location: Location, }, InvalidBinaryBase64 { location: Location, }, BinaryNotUtf8 { location: Location, }, TaggedScalarCannotDeserializeIntoString { location: Location, }, UnexpectedSequenceEnd { location: Location, }, UnexpectedMappingEnd { location: Location, }, InvalidBooleanStrict { location: Location, }, InvalidCharNull { location: Location, }, InvalidCharNotSingleScalar { location: Location, }, NullIntoString { location: Location, }, BytesNotSupportedMissingBinaryTag { location: Location, }, UnexpectedValueForUnit { location: Location, }, ExpectedEmptyMappingForUnitStruct { location: Location, }, UnexpectedContainerEndWhileSkippingNode { location: Location, }, InternalSeedReusedForMapKey { location: Location, }, ValueRequestedBeforeKey { location: Location, }, ExpectedStringKeyForExternallyTaggedEnum { location: Location, }, ExternallyTaggedEnumExpectedScalarOrMapping { location: Location, }, UnexpectedValueForUnitEnumVariant { location: Location, }, InvalidUtf8Input, AliasReplayCounterOverflow { location: Location, }, AliasReplayLimitExceeded { total_replayed_events: usize, max_total_replayed_events: usize, location: Location, }, AliasExpansionLimitExceeded { anchor_id: usize, expansions: usize, max_expansions_per_anchor: usize, location: Location, }, AliasReplayStackDepthExceeded { depth: usize, max_depth: usize, location: Location, }, FoldedBlockScalarMustIndentContent { location: Location, }, InternalDepthUnderflow { location: Location, }, InternalRecursionStackEmpty { location: Location, }, RecursiveReferencesRequireWeakTypes { location: Location, }, InvalidScalar { ty: &'static str, location: Location, }, NonFiniteFloat { value: String, location: Location, }, SerdeInvalidType { unexpected: String, expected: String, location: Location, }, SerdeInvalidValue { unexpected: String, expected: String, location: Location, }, SerdeInvalidLength { len: usize, expected: String, location: Location, }, SerdeUnknownVariant { variant: String, expected: Vec<&'static str>, location: Location, }, SerdeUnknownField { field: String, expected: Vec<&'static str>, location: Location, }, SerdeMissingField { field: &'static str, location: Location, }, UnexpectedContainerEndWhileReadingKeyNode { location: Location, }, DuplicateMappingKey { key: Option<String>, location: Location, }, TaggedEnumMismatch { tagged: String, target: &'static str, location: Location, }, SerdeVariantId { msg: String, location: Location, }, ExpectedMappingEndAfterEnumVariantValue { location: Location, }, ContainerEndMismatch { location: Location, }, UnknownAnchor { location: Location, }, CyclicInclude { id: String, stack: Vec<String>, location: Location, }, UnsupportedIncludeForm { location: Location, }, ResolverError { target: String, error: IncludeResolveError, stack: Vec<String>, location: Location, }, AliasError { msg: String, error: Box<Error>, locations: Locations, }, HookError { msg: String, location: Location, }, UnresolvedProperty { name: String, location: Location, }, InvalidPropertyName { name: String, location: Location, }, PropertyRequiredButUnset { name: String, message: String, location: Location, }, PropertyRequiredButEmpty { name: String, message: String, location: Location, }, Budget { breach: BudgetBreach, location: Location, }, IOError { cause: Error, }, QuotingRequired { value: String, location: Location, }, CannotBorrowTransformedString { reason: TransformReason, location: Location, }, IndentationError { required: RequireIndent, actual: usize, location: Location, }, WithSnippet { regions: Vec<CroppedRegion>, crop_radius: usize, error: Box<Error>, }, UnsupportedTag { tag: String, location: Location, }, TaggedStructFieldName { tag: String, location: Location, },
}
Expand description

Error type compatible with serde::de::Error.

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

Message

Free-form error with optional source location.

Fields

§location: Location
§

InvalidOptions

Invalid deserializer options were provided.

Fields

§location: Location
§

ExternalMessage

Text primarily produced by a dependency (parser / validators).

Renderers should call Localizer::override_external_message to allow callers to replace or translate this text.

Fields

§source: Box<ExternalMessageSource>

Dependency that produced the message and any structured source error.

This is boxed to keep Error below Clippy’s large-error threshold.

§code: Option<String>

Stable-ish identifier when available (e.g. validator error code).

§params: Vec<(String, String)>

Optional structured parameters when available.

§location: Location
§

Eof

Unexpected end of input.

Fields

§location: Location
§

MultipleDocuments

More than one YAML document was found when a single document was expected.

This is typically returned by single-document entrypoints like from_str* / from_slice* / read_to_end* when the input stream contains multiple ----delimited documents.

Fields

§hint: &'static str

Developer-facing hint (may mention specific APIs).

§location: Location
§

Unexpected

Structural/type mismatch — something else than the expected token/value was seen.

Fields

§expected: &'static str
§location: Location
§

MergeValueNotMapOrSeqOfMaps

YAML merge (<<) value was not a mapping or a sequence of mappings.

Fields

§location: Location
§

MergeKeyNotAllowed

YAML merge keys (<<) are disabled by policy.

Fields

§location: Location
§

InvalidBinaryBase64

!!binary scalar could not be decoded as base64.

Fields

§location: Location
§

BinaryNotUtf8

!!binary scalar decoded successfully but was not valid UTF-8 when a string was expected.

Fields

§location: Location
§

TaggedScalarCannotDeserializeIntoString

A scalar was explicitly tagged but could not be deserialized into a string.

Fields

§location: Location
§

UnexpectedSequenceEnd

Encountered a sequence end where it was not expected.

Fields

§location: Location
§

UnexpectedMappingEnd

Encountered a mapping end where it was not expected.

Fields

§location: Location
§

InvalidBooleanStrict

Invalid boolean literal in strict mode.

Fields

§location: Location
§

InvalidCharNull

Invalid char: null cannot be deserialized into char.

Fields

§location: Location
§

InvalidCharNotSingleScalar

Invalid char: expected a single Unicode scalar value.

Fields

§location: Location
§

NullIntoString

Cannot deserialize null into string.

Fields

§location: Location
§

BytesNotSupportedMissingBinaryTag

Bytes (&[u8] / Vec<u8>) are not supported unless the scalar is tagged as !!binary.

Fields

§location: Location
§

UnexpectedValueForUnit

Unexpected value for unit (()).

Fields

§location: Location
§

ExpectedEmptyMappingForUnitStruct

Unit struct expected an empty mapping.

Fields

§location: Location
§

UnexpectedContainerEndWhileSkippingNode

While skipping a node, a container end event was encountered unexpectedly.

Fields

§location: Location
§

InternalSeedReusedForMapKey

Internal error: a seed was reused for a map key.

Fields

§location: Location
§

ValueRequestedBeforeKey

Internal error: value requested before key.

Fields

§location: Location
§

ExpectedStringKeyForExternallyTaggedEnum

Externally tagged enum: expected a string key.

Fields

§location: Location
§

ExternallyTaggedEnumExpectedScalarOrMapping

Externally tagged enum: expected either a scalar or a mapping.

Fields

§location: Location
§

UnexpectedValueForUnitEnumVariant

Unexpected value for unit enum variant.

Fields

§location: Location
§

InvalidUtf8Input

Input was not valid UTF-8.

§

AliasReplayCounterOverflow

Alias replay counter overflow.

Fields

§location: Location
§

AliasReplayLimitExceeded

Alias replay total event limit exceeded.

Fields

§total_replayed_events: usize
§max_total_replayed_events: usize
§location: Location
§

AliasExpansionLimitExceeded

Alias expansion limit exceeded for a single anchor.

Fields

§anchor_id: usize
§expansions: usize
§max_expansions_per_anchor: usize
§location: Location
§

AliasReplayStackDepthExceeded

Alias replay stack depth limit exceeded.

Fields

§depth: usize
§max_depth: usize
§location: Location
§

FoldedBlockScalarMustIndentContent

Folded block scalars must indent their content.

Fields

§location: Location
§

InternalDepthUnderflow

Internal: depth counter underflow.

Fields

§location: Location
§

InternalRecursionStackEmpty

Internal: recursion stack empty.

Fields

§location: Location
§

RecursiveReferencesRequireWeakTypes

recursive references require weak recursion types.

Fields

§location: Location
§

InvalidScalar

Scalar parsing failed for the requested target type.

Fields

§ty: &'static str
§location: Location
§

NonFiniteFloat

In a typeless position (e.g. deserialize_any targeting serde_json::Value), a scalar resolved to a non-finite float — NaN, ±Inf, or a decimal literal that overflows f64 to infinity (e.g. 1e999) — and the effective NonFiniteFloatPolicy is Reject, rejecting it before passing it to the visitor.

Fields

§value: String

The offending scalar text as it appeared in the source (e.g. .nan, 1e999).

§location: Location
§

SerdeInvalidType

Serde-generated: invalid type.

Fields

§unexpected: String
§expected: String
§location: Location
§

SerdeInvalidValue

Serde-generated: invalid value.

Fields

§unexpected: String
§expected: String
§location: Location
§

SerdeInvalidLength

Serde-generated: invalid sequence or container length.

Fields

§len: usize

Invalid length reported by the deserializer or visitor.

§expected: String

Description of the expected value supplied by Serde’s visitor.

§location: Location
§

SerdeUnknownVariant

Serde-generated: unknown enum variant.

Fields

§variant: String
§expected: Vec<&'static str>
§location: Location
§

SerdeUnknownField

Serde-generated: unknown field.

Fields

§field: String
§expected: Vec<&'static str>
§location: Location
§

SerdeMissingField

Serde-generated: missing required field.

Fields

§field: &'static str
§location: Location
§

UnexpectedContainerEndWhileReadingKeyNode

Encountered the end of a sequence or mapping while reading a key node.

This indicates a structural mismatch in the input.

Fields

§location: Location
§

DuplicateMappingKey

Duplicate key in a mapping.

When the duplicate key can be rendered as a string-like scalar, key is provided.

Fields

§location: Location
§

TaggedEnumMismatch

Tagged enum name does not match the target enum.

Fields

§tagged: String
§target: &'static str
§location: Location
§

SerdeVariantId

Serde-generated error while deserializing an enum variant identifier.

Fields

§location: Location
§

ExpectedMappingEndAfterEnumVariantValue

Expected the end of a mapping after an externally tagged enum variant value.

Fields

§location: Location
§

ContainerEndMismatch

Fields

§location: Location
§

UnknownAnchor

Alias references a non-existent anchor.

Fields

§location: Location
§

CyclicInclude

Cyclic include detected.

Fields

§stack: Vec<String>
§location: Location
§

UnsupportedIncludeForm

!include currently only supports the scalar form: !include <path>

Fields

§location: Location
§

ResolverError

Failed to resolve include

Fields

§target: String
§stack: Vec<String>
§location: Location
§

AliasError

Error related to an alias, with both reference (use-site) and defined (anchor) locations.

error keeps the original error, so it renders with the active MessageFormatter and Localizer, and std::error::Error::source returns it.

Fields

§msg: String
👎Deprecated since 2.0.0:

use error to access the original error

Default-rendered inner error retained for existing message-based handlers.

The deserializer still populates this field, but renderers use error instead.

§error: Box<Error>

Original error, including its type and source location.

§locations: Locations
§

HookError

Error when parsing robotic and other extensions beyond standard YAML. (error in extension hook).

Fields

§location: Location
§

UnresolvedProperty

A ${NAME} property reference could not be resolved from the configured property map.

Fields

§name: String

Property name that was requested.

§location: Location
§

InvalidPropertyName

A ${...} property candidate used an invalid property name.

Fields

§name: String

The invalid ${...} candidate as it appeared in the YAML source.

§location: Location
§

PropertyRequiredButUnset

A ${NAME?text} or ${NAME:?text} reference required a value but the property was unset. message may be empty. Hints containing non-empty property-map values preserve their original source text instead of exposing the resolved values.

Fields

§name: String
§message: String
§location: Location
§

PropertyRequiredButEmpty

A ${NAME:?text} reference required a non-empty value but the property was present and empty. message may be empty. Hints containing non-empty property-map values preserve their original source text instead of exposing the resolved values.

Fields

§name: String
§message: String
§location: Location
§

Budget

A YAML budget limit was exceeded.

Fields

§location: Location
§

IOError

Unexpected I/O error. This may happen only when deserializing from a reader.

The default display is IO error; std::error::Error::source provides the underlying cause so error chains do not repeat its message.

Fields

§cause: Error
§

QuotingRequired

The value is targeted to the string field but can be interpreted as a number or boolean. This error can only happen if no_schema set true.

Fields

§value: String
§location: Location
§

CannotBorrowTransformedString

The target type requires a borrowed string (&str), but the value was transformed during parsing (e.g., through escape processing, line folding, or multi-line normalization) and cannot be borrowed from the input.

Use String or Cow<str> instead of &str to handle transformed values.

Fields

§reason: TransformReason

The reason why the string had to be transformed and cannot be borrowed.

§location: Location
§

IndentationError

Indentation does not meet the configured RequireIndent requirement.

Fields

§required: RequireIndent

The indentation requirement that was violated.

§actual: usize

The actual indentation (in spaces) that was found.

§location: Location
§

WithSnippet

Wrap an error with the full input text, enabling rustc-like snippet rendering.

Fields

§regions: Vec<CroppedRegion>

Cropped source windows used for snippet rendering.

This intentionally does NOT store the full input text, to avoid retaining large YAML inputs inside errors.

§crop_radius: usize
§error: Box<Error>
§

UnsupportedTag

An explicitly specified YAML tag is not supported by this crate.

Fields

§location: Location
§

TaggedStructFieldName

A struct field name’s explicit tag violates the enabled crate::Options::reject_tagged_field_names policy.

Fields

§location: Location

Implementations§

Source§

impl Error

Source

pub fn without_snippet(&self) -> &Self

Provide “no snippet” version for cases when snippet rendering is not desired.

Source

pub fn render(&self) -> String

Render this error using the built-in developer formatter.

This is the deferred-rendering entrypoint. It is equivalent to Display/to_string() output, but also allows callers to choose a custom MessageFormatter via Error::render_with_options.

Source

pub fn render_with_formatter(&self, formatter: &dyn MessageFormatter) -> String

Render this error using a custom message formatter.

Source

pub fn render_with_options(&self, options: RenderOptions<'_>) -> String

Render this error using the provided options.

To append to an existing writer, use Error::render_to.

Source

pub fn render_to<W: Write + ?Sized>( &self, writer: &mut W, options: RenderOptions<'_>, ) -> Result

Append this error to writer using the provided rendering options.

Produces the same text as Error::render_with_options without first collecting the complete output in an intermediate String. Message formatters and snippet rendering still perform their own allocations.

Returns fmt::Result, propagating any error from writer. On failure, the writer may already contain part of the rendered error.

let err = serde_saphyr::from_str::<u16>("eighty").unwrap_err();
let mut output = String::from("invalid configuration: ");
err.render_to(&mut output, serde_saphyr::render_options! {
    source_name: Some("config.yaml"),
})?;
assert!(output.starts_with("invalid configuration: "));
assert!(output.contains("config.yaml:1:1"));
Source

pub fn cannot_borrow_transformed(reason: TransformReason) -> Self

Construct a CannotBorrowTransformedString error for the given reason.

This error is returned when deserializing to &str but the string value was transformed during parsing and cannot be borrowed from the input.

Source

pub fn location(&self) -> Option<Location>

If the error has a known location, return it.

Returns:

  • Some(Location) when coordinates are known; None otherwise.

Used by:

  • Callers that want to surface precise positions to users.
Source

pub fn locations(&self) -> Option<Locations>

Return a pair of locations associated with this error.

  • For syntax and other errors that carry a single Location, this returns two identical locations.

  • For validation errors (when the garde / validator feature is enabled), this returns the (reference_location, defined_location) pair for the first validation entry.

    These two locations may differ when YAML anchors/aliases are involved.

  • Returns None when no meaningful location information is available.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

Source§

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

Snippet wrappers forward the wrapped error’s cause to avoid duplicate messages. Use Error::without_snippet to inspect the wrapped error itself. As an exception, Error::AliasError and its snippet wrappers return the wrapped error directly to preserve the existing source chain. I/O errors return their underlying std::io::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
Source§

impl Error for Error

Source§

fn custom<T: Display>(msg: T) -> Self

Raised when there is general error when deserializing a type. Read more
Source§

fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self

Raised when a Deserialize receives a type different from what it was expecting. Read more
Source§

fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self

Raised when a Deserialize receives a value of the right type but that is wrong for some other reason. Read more
Source§

fn invalid_length(len: usize, exp: &dyn Expected) -> Self

Raised when deserializing a sequence or map and the input data contains too many or too few elements. Read more
Source§

fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self

Raised when a Deserialize enum type received a variant with an unrecognized name.
Source§

fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self

Raised when a Deserialize struct type received a field with an unrecognized name.
Source§

fn missing_field(field: &'static str) -> Self

Raised when a Deserialize struct type expected to receive a required field with a particular name but that field was not present in the input.
Source§

fn duplicate_field(field: &'static str) -> Self

Raised when a Deserialize struct type received more than one of the same field.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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.