TINKERPOP-1644 Fix exception handling.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/17a72e0e Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/17a72e0e Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/17a72e0e Branch: refs/heads/TINKERPOP-1642 Commit: 17a72e0e1db6fe52d3a0821ef2bfae1eb39be856 Parents: 18778e4 Author: BrynCooke <[email protected]> Authored: Wed Mar 8 13:23:30 2017 +0000 Committer: Stephen Mallette <[email protected]> Committed: Fri Mar 10 11:12:36 2017 -0500 ---------------------------------------------------------------------- .../jsr223/GremlinGroovyScriptEngine.java | 33 ++++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/17a72e0e/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java index 51850ad..2151a82 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java @@ -168,26 +168,25 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl @Override public Future<Class> load(String script) throws Exception { long start = System.currentTimeMillis(); - try { - return CompletableFuture.supplyAsync(() -> loader.parseClass(script, generateScriptName()), command -> command.run()); - } catch (Exception e) { - if (e.getCause() instanceof CompilationFailedException) { + + return CompletableFuture.supplyAsync(() -> { + try { + return loader.parseClass(script, generateScriptName()); + } catch (CompilationFailedException e) { long finish = System.currentTimeMillis(); log.error("Script compilation FAILED {} took {}ms {}", script, finish - start, e.getCause()); - throw (CompilationFailedException) e.getCause(); - } else { - throw new AssertionError("Unexpected exception when compiling script", e); - } - } finally { - long time = System.currentTimeMillis() - start; - if (time > 5000) { - //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong. - //Scripts with a large numbers of parameters often trigger this and should be avoided. - log.warn("Script compilation {} took {}ms", script, time); - } else { - log.debug("Script compilation {} took {}ms", script, time); + throw e; + } finally { + long time = System.currentTimeMillis() - start; + if (time > 5000) { + //We warn if a script took longer than a few seconds. Repeatedly seeing these warnings is a sign that something is wrong. + //Scripts with a large numbers of parameters often trigger this and should be avoided. + log.warn("Script compilation {} took {}ms", script, time); + } else { + log.debug("Script compilation {} took {}ms", script, time); + } } - } + }, command -> command.run()); } });
