Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 57 variants Message { msg: String, location: Location, }, ExternalMessage { source: 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, }, 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, }, SerdeInvalidType { unexpected: String, expected: String, location: Location, }, SerdeInvalidValue { unexpected: String, 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, }, AliasError { msg: String, locations: Locations, }, HookError { msg: String, location: Location, }, Budget { breach: BudgetBreach, location: Location, }, IOError { cause: Error, }, QuotingRequired { value: String, location: Location, }, CannotBorrowTransformedString { reason: TransformReason, location: Location, }, WithSnippet { regions: Vec<CroppedRegion>, crop_radius: usize, error: Box<Error>, }, ValidationError { report: Report, locations: PathMap, }, ValidationErrors { errors: Vec<Error>, }, ValidatorError { errors: ValidationErrors, locations: PathMap, }, ValidatorErrors { errors: Vec<Error>, },
}
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
§

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

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

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
§

SerdeInvalidType

Serde-generated: invalid type.

Fields

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

SerdeInvalidValue

Serde-generated: invalid value.

Fields

§unexpected: String
§expected: String
§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
§

AliasError

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

This variant allows reporting both where an alias is used and where the anchor is defined, which is useful for errors that occur when deserializing aliased values.

Fields

§locations: Locations
§

HookError

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

Fields

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

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
§

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

ValidationError

Garde validation failure.

Fields

§report: Report
§locations: PathMap
§

ValidationErrors

Garde validation failures (multiple, if multiple validations fail)

Fields

§errors: Vec<Error>
§

ValidatorError

Validator validation failure.

Fields

§locations: PathMap
§

ValidatorErrors

Validator validation failures (multiple, if multiple validations fail)

Fields

§errors: Vec<Error>

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.

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

1.30.0 · Source§

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

Returns the lower-level source of this error, if any. Read more
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 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 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 duplicate_field(field: &'static str) -> Self

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

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe 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<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> ToCompactString for T
where T: Display,

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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP