Closed TedDriggs closed 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 :)
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.
My fix for this in the past has been twofold:
Result
type for parsing options, and aVec
for collecting all errors encountered during parsing. The error type should be remembering the span where the error was encountered.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
. Thedarling::Error
type has the functionality you'd need for this, though you could also directly wrapsyn
's error if you want to keep the dependency list small.