Skip to content

Commit

Permalink
Fix: #[Query]
Browse files Browse the repository at this point in the history
  • Loading branch information
kanarus committed Dec 25, 2023
1 parent fc359b8 commit 2e6b17f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ohkami_macros/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn impl_payload_formdata(data: &ItemStruct) -> Result<TokenStream> {

// `#[Payload(Form)]` doesn't accept optional fields
if fields_data.iter().any(|FieldData { is_optional, .. }| *is_optional) {
return Err(syn::Error::new(Span::mixed_site(), "`Option<_>` is not available in `#[Payload(FormData)]`"))
return Err(syn::Error::new(Span::mixed_site(), "`Option<_>` is not available in `#[Payload(Form)]`"))
}

let declaring_exprs = {
Expand Down Expand Up @@ -152,7 +152,7 @@ fn impl_payload_formdata(data: &ItemStruct) -> Result<TokenStream> {
"String" => PartType::Field,
"File" | "utils::File" | "ohkami::File" | "::ohkami::File" => PartType::File,
"Vec<File>" | "Vec<utils::File>" | "Vec<ohkami::utils::File>" | "Vec<::ohkami::utils::File>" => PartType::Files,
unexpected => return Err(syn::Error::new(Span::call_site(), &format!("Unexpected field type `{unexpected}` : `#[Payload(FormData)]` supports only `String`, `File` or `Vec<File>` as field type")))
unexpected => return Err(syn::Error::new(Span::call_site(), &format!("Unexpected field type `{unexpected}` : `#[Payload(Form)]` supports only `String`, `File` or `Vec<File>` as field type")))
}.into_method_call();

Ok(quote!{
Expand Down
4 changes: 2 additions & 2 deletions ohkami_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ pub(super) fn Query(data: TokenStream) -> Result<TokenStream> {
quote!{
#field_name: req.query::<#inner_type>(#field_name_str) // Option<Result<_>>
.transpose()
.map_err(|e| e.to_string().into())?,
.map_err(|e| ::std::borrow::Cow::Owned(e.to_string()))?,
}
} else {
quote!{
#field_name: req.query::<#field_type>(#field_name_str) // Option<Result<_>>
.ok_or_else(|| ::std::borrow::Cow::Borrowed(
concat!("Expected query parameter `", #field_name_str, "`")
))?
.map_err(|e| e.to_string().into())?,
.map_err(|e| ::std::borrow::Cow::Owned(e.to_string()))?,
}
}
});
Expand Down

0 comments on commit 2e6b17f

Please sign in to comment.