Enum knuffel::errors::DecodeError
source · [−]#[non_exhaustive]
pub enum DecodeError<S: ErrorSpan> {
TypeName {
span: S,
found: Option<TypeName>,
expected: ExpectedType,
rust_type: &'static str,
},
ScalarKind {
span: S,
expected: ExpectedKind,
found: Kind,
},
Missing {
span: S,
message: String,
},
MissingNode {
message: String,
},
Unexpected {
span: S,
kind: &'static str,
message: String,
},
Conversion {
span: S,
source: Box<dyn Error + Send + Sync + 'static>,
},
Unsupported {
span: S,
message: Cow<'static, str>,
},
Custom(Box<dyn Error + Send + Sync + 'static>),
}Expand description
An error type that is returned by decoder traits and emitted to the context
These are elements of the
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
TypeName
Fields
expected: ExpectedTypeExpected type name or type names
rust_type: &'static strRust type that is being decoded when error is encountered
Unexpected type name encountered
Type names are identifiers and strings in parenthesis before node names or values.
ScalarKind
Fields
expected: ExpectedKindScalar kind (or multiple) expected at this position
found: KindKind of scalar that is found
Different scalar kind was encountered than expected
This is emitted when integer is used instead of string, and similar. It
may also be encountered when null is used for non-optional field.
Missing
Fields
message: StringDescription of what’s missing
Some required element is missing
This is emitted on missing required attributes, properties, or children.
(missing type names are emitted using DecodeError::TypeName)
MissingNode
Fields
message: StringDescriptino of what’s missing
Missing named node at top level
This is similar to Missing but is only emitted for nodes on the
document level. This is separate error because there is no way to show
span where missing node is expected (end of input is not very helpful).
Unexpected
Unexpected entity encountered
This is emitted for entities (arguments, properties, children) that have to matching structure field to put into, and also for nodes that aren expected to be encountered twice.
Conversion
Fields
Bad scalar conversion
This error is emitted when some scalar value of right kind cannot be converted to the Rust value. Including, but not limited to:
- Integer value out of range
FromStrreturned error for the value parse by#[knuffel(.., str)]
Unsupported
Fields
Unsupported value
This is currently used to error out on (base64) values when base64
feature is not enabled.
Custom(Box<dyn Error + Send + Sync + 'static>)
Custom error that can be emitted during decoding
This is not used by the knuffel itself. Note most of the time it’s
better to use DecodeError::Conversion as that will associate
source code span to the error.
Implementations
sourceimpl<S: ErrorSpan> DecodeError<S>
impl<S: ErrorSpan> DecodeError<S>
sourcepub fn conversion<T, E>(span: &Spanned<T, S>, err: E) -> Self where
E: Into<Box<dyn Error + Send + Sync + 'static>>,
pub fn conversion<T, E>(span: &Spanned<T, S>, err: E) -> Self where
E: Into<Box<dyn Error + Send + Sync + 'static>>,
Construct DecodeError::Conversion error
sourcepub fn scalar_kind(expected: Kind, found: &Spanned<Literal, S>) -> Self
pub fn scalar_kind(expected: Kind, found: &Spanned<Literal, S>) -> Self
Construct DecodeError::ScalarKind error
sourcepub fn missing(node: &SpannedNode<S>, message: impl Into<String>) -> Self
pub fn missing(node: &SpannedNode<S>, message: impl Into<String>) -> Self
Construct DecodeError::Missing error
sourcepub fn unexpected<T>(
elem: &Spanned<T, S>,
kind: &'static str,
message: impl Into<String>
) -> Self
pub fn unexpected<T>(
elem: &Spanned<T, S>,
kind: &'static str,
message: impl Into<String>
) -> Self
Construct DecodeError::Unexpected error
sourcepub fn unsupported<T, M>(span: &Spanned<T, S>, message: M) -> Self where
M: Into<Cow<'static, str>>,
pub fn unsupported<T, M>(span: &Spanned<T, S>, message: M) -> Self where
M: Into<Cow<'static, str>>,
Construct DecodeError::Unsupported error
Trait Implementations
sourceimpl<S: Debug + ErrorSpan> Debug for DecodeError<S>
impl<S: Debug + ErrorSpan> Debug for DecodeError<S>
sourceimpl<S: ErrorSpan> Diagnostic for DecodeError<S>
impl<S: ErrorSpan> Diagnostic for DecodeError<S>
sourcefn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan>>>
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan>>>
Labels to apply to this Diagnostic’s Diagnostic::source_code
sourcefn code(&'a self) -> Option<Box<dyn Display + 'a, Global>>
fn code(&'a self) -> Option<Box<dyn Display + 'a, Global>>
Unique diagnostic code that can be used to look up more information
about this Diagnostic. Ideally also globally unique, and documented
in the toplevel crate’s documentation for easy searching. Rust path
format (foo::bar::baz) is recommended, but more classic codes like
E0123 or enums will work just fine. Read more
sourcefn severity(&self) -> Option<Severity>
fn severity(&self) -> Option<Severity>
Diagnostic severity. This may be used by
ReportHandlers to change the display format
of this diagnostic. Read more
sourcefn help(&'a self) -> Option<Box<dyn Display + 'a, Global>>
fn help(&'a self) -> Option<Box<dyn Display + 'a, Global>>
Additional help text related to this Diagnostic. Do you have any
advice for the poor soul who’s just run into this issue? Read more
sourcefn url(&'a self) -> Option<Box<dyn Display + 'a, Global>>
fn url(&'a self) -> Option<Box<dyn Display + 'a, Global>>
URL to visit for a more detailed explanation/help about this
Diagnostic. Read more
sourcefn source_code(&self) -> Option<&dyn SourceCode>
fn source_code(&self) -> Option<&dyn SourceCode>
Source code to apply this Diagnostic’s Diagnostic::labels to.
Additional related Diagnostics.
sourceimpl<S: ErrorSpan> Display for DecodeError<S>
impl<S: ErrorSpan> Display for DecodeError<S>
sourceimpl<S: ErrorSpan> Error for DecodeError<S> where
Self: Debug + Display,
impl<S: ErrorSpan> Error for DecodeError<S> where
Self: Debug + Display,
sourcefn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
sourcefn backtrace(&self) -> Option<&Backtrace>
fn backtrace(&self) -> Option<&Backtrace>
backtrace)Returns a stack backtrace, if available, of where this error occurred. Read more
1.0.0 · sourcefn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations
impl<S> !RefUnwindSafe for DecodeError<S>
impl<S> Send for DecodeError<S>
impl<S> Sync for DecodeError<S>
impl<S> Unpin for DecodeError<S> where
S: Unpin,
impl<S> !UnwindSafe for DecodeError<S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more