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

Improve error message in case too much nesting #29

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rinja_parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -711,10 +711,10 @@ pub(crate) struct Level(u8);
impl Level {
fn nest(self, i: &str) -> ParseResult<'_, Level> {
if self.0 >= Self::MAX_DEPTH {
return Err(ErrorContext::from_err(nom::Err::Failure(error_position!(
return Err(nom::Err::Failure(ErrorContext::new(
"your template code is too deeply nested, or last expression is too complex",
i,
ErrorKind::TooLarge
))));
)));
}

Ok((i, Level(self.0 + 1)))
3 changes: 2 additions & 1 deletion testing/tests/ui/excessive_nesting.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
error: failed to parse template source at row 14, column 42 near:
error: your template code is too deeply nested, or last expression is too complex
failed to parse template source at row 14, column 42 near:
"%}{%if 1%}{%if 1%}{%if 1%}{%if 1%}{%if 1"...
--> tests/ui/excessive_nesting.rs:3:10
|
5 changes: 3 additions & 2 deletions testing/tests/ui/filter-recursion.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
error: failed to parse template source
--> testing/templates/filter-recursion.html:1:255
error: your template code is too deeply nested, or last expression is too complex
failed to parse template source
--> testing/templates/filter-recursion.html:1:255
"|A|AA|A|A|A|A|AA|A|A|A|A|AA|A|A|A|A|AA|A"...
--> tests/ui/filter-recursion.rs:3:10
|