@Override public String getMessage() { return format("line %s:%s: %s", getLineNumber(), getColumnNumber(), getErrorMessage()); } }
@Override public String getMessage() { return format("line %s:%s: %s", getLineNumber(), getColumnNumber(), getErrorMessage()); } }
@Test public void testParsingExceptionPositionInfo() { try { SQL_PARSER.createStatement("select *\nfrom x\nwhere from"); fail("expected exception"); } catch (ParsingException e) { assertTrue(e.getMessage().startsWith("line 3:7: mismatched input 'from'")); assertTrue(e.getErrorMessage().startsWith("mismatched input 'from'")); assertEquals(e.getLineNumber(), 3); assertEquals(e.getColumnNumber(), 7); } }
@Nullable private static ErrorLocation getErrorLocation(Throwable throwable) { // TODO: this is a big hack if (throwable instanceof ParsingException) { ParsingException e = (ParsingException) throwable; return new ErrorLocation(e.getLineNumber(), e.getColumnNumber()); } else if (throwable instanceof SemanticException) { SemanticException e = (SemanticException) throwable; if (e.getNode().getLocation().isPresent()) { NodeLocation nodeLocation = e.getNode().getLocation().get(); return new ErrorLocation(nodeLocation.getLineNumber(), nodeLocation.getColumnNumber()); } } return null; }
@Nullable private static ErrorLocation getErrorLocation(Throwable throwable) { // TODO: this is a big hack if (throwable instanceof ParsingException) { ParsingException e = (ParsingException) throwable; return new ErrorLocation(e.getLineNumber(), e.getColumnNumber()); } else if (throwable instanceof SemanticException) { SemanticException e = (SemanticException) throwable; if (e.getNode().getLocation().isPresent()) { NodeLocation nodeLocation = e.getNode().getLocation().get(); return new ErrorLocation(nodeLocation.getLineNumber(), nodeLocation.getColumnNumber()); } } return null; }