Skip to content

Commit

Permalink
Merge pull request #29 from GuillaumeGomez/improve-ui-error
Browse files Browse the repository at this point in the history
Improve error message in case too much nesting
  • Loading branch information
Kijewski authored Jun 23, 2024
2 parents 704c506 + 1f1cff0 commit bd36c4b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions rinja_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
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
|
Expand Down
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
|
Expand Down

0 comments on commit bd36c4b

Please sign in to comment.