Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field_error improved, Boxed error kind, explicit naming also for DecodeErrorKind #197

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions macros/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::{Deref, Neg};
use std::ops::Deref;

use quote::ToTokens;
use syn::{Lit, NestedMeta, Path, UnOp};
Expand Down Expand Up @@ -937,7 +937,7 @@ impl<'a> FieldConfig<'a> {
.unwrap_or_else(|| context.to_string())
);

let or_else = quote!(.map_err(|error| #crate_root::de::Error::field_error(#ident, error, decoder.codec()))?);
let or_else = quote!(.map_err(|error| #crate_root::de::Error::field_error(#ident, error.into(), decoder.codec()))?);
let default_fn = self.default.as_ref().map(|default_fn| match default_fn {
Some(path) => quote!(#path),
None => quote!(<#ty>::default),
Expand All @@ -946,7 +946,7 @@ impl<'a> FieldConfig<'a> {
let tag = self.tag(context);
let constraints = self.constraints.const_expr(crate_root);
let handle_extension = if self.is_not_option_or_default_type() {
quote!(.ok_or_else(|| #crate_root::de::Error::field_error(#ident, "extension required but not present", decoder.codec()))?)
quote!(.ok_or_else(|| #crate_root::de::Error::field_error(#ident, crate::error::DecodeError::extension_present_but_not_required(#tag, decoder.codec()), decoder.codec()))?)
} else if self.is_default_type() {
quote!(.unwrap_or_else(#default_fn))
} else {
Expand Down
6 changes: 1 addition & 5 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,7 @@ pub trait Error: core::fmt::Display {
/// Creates a new error about being unable to decode a field in a compound
/// type, such as a set or sequence.
#[must_use]
fn field_error<D: core::fmt::Display>(
name: &'static str,
error: D,
codec: crate::Codec,
) -> Self;
fn field_error(name: &'static str, error: DecodeError, codec: crate::Codec) -> Self;
/// Creates a new error about finding a duplicate field.
#[must_use]
fn duplicate_field(name: &'static str, codec: crate::Codec) -> Self;
Expand Down
Loading