From 614d7801a48b5a75f21606527d3c90830dcdfc34 Mon Sep 17 00:00:00 2001 From: xvrl Date: Tue, 5 Mar 2013 12:41:44 -0800 Subject: [PATCH] very simplistic error handling --- .../main/java/com/metamx/druid/sql/SQLRunner.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client/src/main/java/com/metamx/druid/sql/SQLRunner.java b/client/src/main/java/com/metamx/druid/sql/SQLRunner.java index fca0a48c101..e2111060b01 100644 --- a/client/src/main/java/com/metamx/druid/sql/SQLRunner.java +++ b/client/src/main/java/com/metamx/druid/sql/SQLRunner.java @@ -20,11 +20,10 @@ import com.metamx.druid.result.TimeseriesResultValue; import com.metamx.druid.sql.antlr4.DruidSQLLexer; import com.metamx.druid.sql.antlr4.DruidSQLParser; import org.antlr.v4.runtime.ANTLRInputStream; -import org.antlr.v4.runtime.BailErrorStrategy; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.ConsoleErrorListener; import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.misc.ParseCancellationException; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; @@ -74,14 +73,20 @@ public class SQLRunner DruidSQLLexer lexer = new DruidSQLLexer(stream); TokenStream tokenStream = new CommonTokenStream(lexer); DruidSQLParser parser = new DruidSQLParser(tokenStream); - parser.setErrorHandler(new BailErrorStrategy()); + lexer.removeErrorListeners(); + parser.removeErrorListeners(); + + lexer.addErrorListener(ConsoleErrorListener.INSTANCE); + parser.addErrorListener(ConsoleErrorListener.INSTANCE); try { DruidSQLParser.QueryContext queryContext = parser.query(); + if(parser.getNumberOfSyntaxErrors() > 0) throw new IllegalStateException(); // parser.setBuildParseTree(true); // System.err.println(q.toStringTree(parser)); - } catch(ParseCancellationException e) { - System.out.println(e.getCause().getMessage()); + } catch(Exception e) { + String msg = e.getMessage(); + if(msg != null) System.err.println(e); System.exit(1); }