Search code examples
logginggroovytitangremlingremlin-server

Logging syntax errors in Groovy scripts in Titan


I'm working on a project that uses graph database Titan. The queries are sent from Python through Gremlin in a form of Groovy scripts. I have access to Titan/Gremlin logs, however, logs provide very little information about syntax (and other) errors. If something wrong with a script, most of the time I get just a notification that it contains a syntax error. In example (I left closing brace absent on purpose):

graph.traversal().V(4096).hasLabel('slot_type').has('name', 'slot_DefTerm'

I just get a message:

WARN  org.apache.tinkerpop.gremlin.server.handler.HttpGremlinEndpointHandler  - Invalid request - responding with 500 Internal Server Error and Error encountered evaluating script: 

graph.traversal().V(4096).hasLabel('slot_type').has('name', 'slot_DefTerm'

Absence of information about a line/column of a mistake (and a description of an error) results in a very slow and painful debugging especially of big scripts and sophisticated errors.

I would like to have something more informative in gremlin log, e.g. logging of syntax error messages from Groovy interpreter. How can I configure Titan to make logging more informative in this way?


Solution

  • I'm not sure if you're just using an older version of Gremlin Server with Titan, but as of TinkerPop 3.2.3 you get fairly robust errors back in the output as well as in the server logs:

    $ curl "http://localhost:8182?gremlin=100/0"
    {"message":"Division by zero","Exception-Class":"java.lang.ArithmeticException"}
    $ curl "http://localhost:8182?gremlin=x=100\nx/0"
    {"message":"startup failed:\nScript4.groovy: 1: unexpected char: '\\' @ line 1, column 6.\n   x=100\\nx/0\n        ^\n\n1 error\n","Exception-Class":"org.codehaus.groovy.control.MultipleCompilationErrorsException"}
    

    Note that the server output is also pretty detailed:

    [WARN] HttpGremlinEndpointHandler - Invalid request - responding with 500 Internal Server Error and startup failed:
    Script4.groovy: 1: unexpected char: '\' @ line 1, column 6.
       x=100\nx/0
            ^
    
    1 error
    
    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
    Script4.groovy: 1: unexpected char: '\' @ line 1, column 6.
       x=100\nx/0
            ^
    
    1 error
    
        at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
        at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
        at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
        at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
        at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:360)
        at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:140)
        at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:111)
        at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:237)
        at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:167)
        at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931)
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
        at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
        at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:211)
        at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.getScriptClass(GremlinGroovyScriptEngine.java:527)
        at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:446)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
        at org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines.eval(ScriptEngines.java:119)
        at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$2(GremlinExecutor.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    

    I suspect this issue may have been a problem in earlier versions of TinkerPop that were shipped with Titan 1.0 and have long since been improved upon.