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

Generate better errors for top level nodes #42

Merged

Conversation

GuillaumeGomez
Copy link
Collaborator

No description provided.

Node::Extends(_) | Node::Macro(_) | Node::Import(_) if !top => {
return Err(CompileError::no_file_info(
"extends, macro or import blocks not allowed below top level",
Node::Extends(e) if !top => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit sad about needing to split this in 3 parts (because the Node isn't the same, so rust isn't happy). But we got a small improvement for this: the error message is now specific to the node type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the same. A name() on node, optionally with a top_level_only(), might reduce the specialization.

The bigger problem I find using Rinja (or Askama) is the lack of context in the error messages for templates. It's nice to know what specific keyword caused the problem but it would be even better if it showed a template line number.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's exactly what this PR adds. Take a look at the error output here. Almost all errors now have context and everything minus a few exceptions. :)

Copy link
Contributor

@softdevca softdevca Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpful, thank you!

Anything else that needs doing for the merge?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting a review from @Kijewski. For now we're two maintainers and we follow the rule to wait for at least one other maintainer's review before merging. So just a bit of patience now. 😉

"#, ext = "txt")]
struct MyTemplate3;

#[derive(Template)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not be the best location for this test as it checks multiple extends rather than blocks not at the top level

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, moving it to its own file.

Node::Extends(_) | Node::Macro(_) | Node::Import(_) if !top => {
return Err(CompileError::no_file_info(
"extends, macro or import blocks not allowed below top level",
Node::Extends(e) if !top => {
Copy link
Contributor

@softdevca softdevca Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpful, thank you!

Anything else that needs doing for the merge?

@GuillaumeGomez GuillaumeGomez force-pushed the top-level-nodes-errors branch from a7b386b to 27e12f0 Compare July 2, 2024 20:15
@GuillaumeGomez GuillaumeGomez requested a review from Kijewski July 2, 2024 20:51
@Kijewski Kijewski force-pushed the top-level-nodes-errors branch from 3daa777 to d4b363b Compare July 2, 2024 23:18
@Kijewski
Copy link
Collaborator

Kijewski commented Jul 2, 2024

Very useful change!

I de-duplicated the top-level check, and getting the FileInfo of a Node a bit.

@GuillaumeGomez
Copy link
Collaborator Author

I can't approve it says github but I like the changes a lot, thanks to both of you!

@GuillaumeGomez GuillaumeGomez merged commit 37c300d into askama-rs:master Jul 3, 2024
17 checks passed
@GuillaumeGomez GuillaumeGomez deleted the top-level-nodes-errors branch July 3, 2024 08:39
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.

3 participants