Use error variant for field duplicates

This commit is contained in:
Dirkjan Ochtman 2022-09-06 23:21:11 +02:00
parent ebc29b5761
commit 6c0cb83189
2 changed files with 4 additions and 2 deletions

View File

@ -259,7 +259,7 @@ impl Deserializer {
tokens.match_.extend(quote!( tokens.match_.extend(quote!(
__Elements::#enum_name => { __Elements::#enum_name => {
if #enum_name.is_some() { if #enum_name.is_some() {
panic!("duplicated value"); return Err(Error::DuplicateValue);
} }
let mut nested = deserializer.nested(data); let mut nested = deserializer.nested(data);
@ -270,7 +270,7 @@ impl Deserializer {
tokens.match_.extend(quote!( tokens.match_.extend(quote!(
__Attributes::#enum_name => { __Attributes::#enum_name => {
if #enum_name.is_some() { if #enum_name.is_some() {
panic!("duplicated value"); return Err(Error::DuplicateValue);
} }
let mut nested = deserializer.for_attr(attr); let mut nested = deserializer.for_attr(attr);

View File

@ -90,4 +90,6 @@ pub enum Error {
ExpectedScalar, ExpectedScalar,
#[error("wrong namespace")] #[error("wrong namespace")]
WrongNamespace, WrongNamespace,
#[error("duplicate value")]
DuplicateValue,
} }