-
-
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
Improve error when whitespace control is used on extends #954
Conversation
I think I'd prefer to improve the error message instead of allowing it in the parser as it could be confusing to have it doing nothing. |
I just realized:
What if I wanted to keep the whitespaces before "hello"? I'd need to add an empty comment right after |
I think the whitespace outside |
Yep, seems like a weird way to handle it. Well, what do you want me to do in this case? |
How hard would it be to emit a good error message for this? Maybe just parse it like it's allowed but then emit an error from the parser if any of the whitespace controls are non-default for |
Pretty easy. Updating. |
dc5b537
to
0af493f
Compare
Done. |
askama_parser/src/node.rs
Outdated
if pws.is_some() || nws.is_some() { | ||
Err(nom::Err::Failure(ErrorContext { | ||
input: start, | ||
message: Some(Cow::Borrowed( | ||
"whitespace control is not allowed on `extends`", | ||
)), | ||
})) | ||
} else { | ||
Ok((i, Self { path })) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd prefer to either write this with an early return (probably for the Ok
case) or just as a match:
match (pws, nws) {
(None, None) => Ok((i, Self { path })),
(_, _) => Err(..),
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Err(nom::Err::Failure(ErrorContext { | ||
input: start, | ||
message: Some(Cow::Borrowed( | ||
"whitespace control is not allowed on `extends`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this mention something about why this is the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum... I think it'd better to mention this in the book instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can live with that.
0af493f
to
ce6ec13
Compare
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for all the nits!
ce6ec13
to
5b8ba88
Compare
Nah it's fine. I don't mind the review rounds. |
Took me a while to understand why
askama
was complaining about anextends
. Realized that it was because whitespace control is not allowed on it. Even though it does nothing, I think it's not great user experience to that this opaque error with valid jinja code so I updated the parser to allow it.