diff --git a/crates/relax-macros/src/lib.rs b/crates/relax-macros/src/lib.rs index d6da2e2..4c715fa 100644 --- a/crates/relax-macros/src/lib.rs +++ b/crates/relax-macros/src/lib.rs @@ -176,9 +176,9 @@ fn derive_impl(input: syn::DeriveInput) -> syn::Result { .any(|attr| attr.path().is_ident("relax")); Ok(match (nested, get_generic_ty("Option", ty).is_some()) { - (false, false) => quote! { #name: value.#name.ok_or(::relax::RequiredFieldNotSet(stringify!(#name)))? }, + (false, false) => quote! { #name: value.#name.ok_or(::relax::RequiredFieldNotSet(concat!("`", stringify!(#name), "` of ", stringify!(#base))))? }, (false, true) => quote! { #name: value.#name }, - (true, false) => quote! { #name: value.#name.ok_or(::relax::RequiredFieldNotSet(stringify!(#name)))?.try_into()? }, + (true, false) => quote! { #name: value.#name.ok_or(::relax::RequiredFieldNotSet(concat!("`", stringify!(#name), "` of ", stringify!(#base))))?.try_into()? }, (true, true) => quote! { #name: value.#name.map(|val| val.try_into()).transpose().ok().flatten() }, }) }).collect::>>()?; diff --git a/crates/relax/src/lib.rs b/crates/relax/src/lib.rs index ee00fc3..20e8db8 100644 --- a/crates/relax/src/lib.rs +++ b/crates/relax/src/lib.rs @@ -17,7 +17,7 @@ pub struct RequiredFieldNotSet(pub &'static str); impl std::fmt::Display for RequiredFieldNotSet { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "required field `{}` is not set", self.0) + write!(f, "required field is not set ({})", self.0) } } impl std::error::Error for RequiredFieldNotSet {}