Skip to content

Commit

Permalink
Merge pull request #155 from pmenhart/master
Browse files Browse the repository at this point in the history
Improved description of parsing errors
  • Loading branch information
bkiers authored Oct 23, 2019
2 parents df531d0 + 6b34dc5 commit 851bd7c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/main/java/liqp/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private ParseTree parse(LiquidLexer lexer) {
lexer.addErrorListener(new BaseErrorListener(){
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
throw new LiquidException(String.format("lexer error on line %s, index %s", line, charPositionInLine), line, charPositionInLine);
throw new LiquidException(String.format("lexer error \"%s\" on line %s, index %s", msg, line, charPositionInLine), line, charPositionInLine, e);
}
});

Expand All @@ -166,7 +166,7 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int
parser.addErrorListener(new BaseErrorListener(){
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
throw new LiquidException(String.format("parser error on line %s, index %s", line, charPositionInLine), line, charPositionInLine);
throw new LiquidException(String.format("parser error \"%s\" on line %s, index %s", msg, line, charPositionInLine), line, charPositionInLine, e);
}
});

Expand Down Expand Up @@ -403,7 +403,11 @@ public String renderUnguarded(final Map<String, Object> variables) {
return rendered == null ? "" : String.valueOf(rendered);
}
catch (Exception e) {
throw new RuntimeException(e);
if (e instanceof RuntimeException) {
throw e;
} else {
throw new RuntimeException(e);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/liqp/exceptions/LiquidException.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public LiquidException(String message, ParserRuleContext ctx) {
this.charPositionInLine = ctx.start.getCharPositionInLine();
}

public LiquidException(String message, int line, int charPositionInLine) {
super(message);
public LiquidException(String message, int line, int charPositionInLine, Throwable cause) {
super(message, cause);
this.line = line;
this.charPositionInLine = charPositionInLine;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/tags/IncludeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void renderTestWithIncludeSubdirectorySpecifiedInLiquidFlavorWithStrictVa
@Test
public void renderTestWithIncludeSubdirectorySpecifiedInLiquidFlavorWithStrictVariablesException() throws Exception {

thrown.expectCause(new NestedCauseMatcher<>(isA(VariableNotExistException.class)));
thrown.expectCause(isA(VariableNotExistException.class));

File index = new File("src/test/jekyll/index_with_variables.html");
Template template = Template.parse(
Expand Down

0 comments on commit 851bd7c

Please sign in to comment.