-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Consider using compile_error!
instead of panicking
#368
Comments
compile_error!
instead of panicingcompile_error!
instead of panicking
The simple approach using what syn provides is not enough because many of the potential panics originate from the template parser, which doesn't process Rust code as such. Still, it would surely be nice to use something better than |
I agree that the spans cannot point to the template code (which I assume is what you mean with not good enough) as that's not processed Rust code, but the error message reported by tools like rust-analyzer would be much more useful if |
Can you explain that with an example? |
Sure. Assuming you confuse programming languages and write
However, rust-analyzer (invoked via lsp-mode) does not print the help message, so I'm left with this in my IDE: If However, if there was a syntax error in the template, I'd still get an error message pointing to the macro invocation:
If spans outside of the derive input were supported (which I don't think is even planned, but I might be wrong) the output could look like this:
which would be ideal but I believe is currently unachievable. |
Ok, I believe this is substantially improved by #373. Let me know if I got anything wrong! |
No, unfortunately it did not, I now get
followed by another error
|
Okay, would you mind making a PR? It should be straightforward to fix from here: https://github.com/djc/askama/blob/main/askama_derive/src/lib.rs#L17 |
I don't know how compile errors are tested, but it would be ideal to have a test for this, too. |
Sure, I've used the |
That's a long list... See the changes in #373. But really I think the integration test is the most important part, so maybe just add one test that tests the case that you started with -- trying to parse a Rust file instead of a template? |
I just tried out askama for the first time and my IDE (using rust-analyzer) reported that my code failed to compile because
proc-macro derive panicked
. This error message is not very helpful as I had to go to the command line and ask cargo what the real problem was. If the derive macro issued acompile_error!(msg)
instead of panicking, the error message would've been correctly reported by rust-analyzer. This is also already built into syn to make life easier.The text was updated successfully, but these errors were encountered: