elichai / log-derive

A procedural macro for auto logging output of functions
https://docs.rs/log-derive
Apache License 2.0
189 stars 12 forks source link

Improve compile-time error messages from log-derive #5

Closed TedDriggs closed 5 years ago

TedDriggs commented 5 years ago

Misspelling a meta-item name (or other errors) cause error messages that highlight the entire attribute and don't clearly spell out what's wrong.

compile error

My fix for this in the past has been twofold:

  1. Have a Result type for parsing options, and a Vec for collecting all errors encountered during parsing. The error type should be remembering the span where the error was encountered.
  2. Before building the Attributes struct, check if the list of errors is empty. If so, emit each error. syn::Error works well for this.

Note that I found this tedious enough that I created a library to help with the bookkeeping, called darling. The darling::Error type has the functionality you'd need for this, though you could also directly wrap syn's error if you want to keep the dependency list small.

elichai commented 5 years ago

Ha. You're saying I should use syn::Error instead of panicking? I was just talking with @dtolnay about compile errors in proc-macros (actually about code errors not erros in the macro, and he pointed me to this: https://github.com/rust-lang/rust/issues/43081 )

I'll look into this.

Thanks for the thorough review and issues :)