Skip to content

Commit

Permalink
feat: use syn error instead of panics
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Dec 18, 2024
1 parent b4aabf7 commit d1fe498
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions parenv-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ pub fn derive_environment(input: TokenStream) -> TokenStream {

let ident = input.ident;
let Data::Struct(struct_data) = input.data else {
panic!("environment parser can only be derived on structs");
return syn::Error::new_spanned(ident, "environment parser can only be derived on structs")
.to_compile_error()
.into();
};
let Fields::Named(fields) = struct_data.fields else {
panic!("environment parser can only be derived on structs whose fields have names");
return syn::Error::new_spanned(
ident,
"environment parser can only be derived on structs whose fields have names",
)
.to_compile_error()
.into();
};

let (prefix, suffix) = parenv_mata_values(&input.attrs);
Expand Down

0 comments on commit d1fe498

Please sign in to comment.