Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFC: Provide best practices for errors #114

Merged
merged 2 commits into from
Jan 5, 2021
Merged

Conversation

TedDriggs
Copy link
Owner

This improves the documentation about how best to use darling::Error

@TedDriggs
Copy link
Owner Author

@chipsenkbeil can you take a look at this?

@TedDriggs
Copy link
Owner Author

TedDriggs commented Jan 5, 2021

@chipsenkbeil correct. darling errors bind to the tightest span they can, so choosing one of them is likely to point to some random field or meta-item, rather than to any usefully-broad span. Using Span::call_site() is the appropriate move for that, though as seen in #110 that will cause the error to point at the macro invocation.

Having looked at entity-rs, I don't see it doing anything that precludes the use of darling::Error for its custom validations after initial parsing. I did see some places where you use the ? operator a function that returns a Result<_, syn::Error>, so I've added a conversion from syn::Error to darling::Error to make that seamless in #116

core/src/error/mod.rs Outdated Show resolved Hide resolved
@TedDriggs TedDriggs merged commit 3232a9b into master Jan 5, 2021
@chipsenkbeil
Copy link
Contributor

@chipsenkbeil correct. darling errors bind to the tightest span they can, so choosing one of them is likely to point to some random field or meta-item, rather than to any usefully-broad span. Using Span::call_site() is the appropriate move for that, though as seen in #110 that will cause the error to point at the macro invocation.

Having looked at entity-rs, I don't see it doing anything that precludes the use of darling::Error for its custom validations after initial parsing. I did see some places where you use the ? operator a function that returns a Result<_, syn::Error>, so I've added a conversion from syn::Error to darling::Error to make that seamless in #116

I'm planning to do a little refactoring to clean up the code and split out the derive into multiple derives, so I can work on switching over to darling::Error at the same time. Thanks for all of the help and patience!

@TedDriggs TedDriggs deleted the error-documentation branch January 5, 2021 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants