@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; }
private void assertFails(Session session, SemanticErrorCode error, Optional<NodeLocation> location, @Language("SQL") String query) { try { analyze(session, query); fail(format("Expected error %s, but analysis succeeded", error)); } catch (SemanticException e) { if (e.getCode() != error) { fail(format("Expected error %s, but found %s: %s", error, e.getCode(), e.getMessage()), e); } if (location.isPresent()) { NodeLocation expected = location.get(); NodeLocation actual = e.getNode().getLocation().get(); if (expected.getLineNumber() != actual.getLineNumber() || expected.getColumnNumber() != actual.getColumnNumber()) { fail(format( "Expected error '%s' to occur at line %s, offset %s, but was: line %s, offset %s", e.getCode(), expected.getLineNumber(), expected.getColumnNumber(), actual.getLineNumber(), actual.getColumnNumber())); } } } }
@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; }