简体   繁体   English

在gremlin-groovy脚本中获取有关异常的行号或完整堆栈跟踪

[英]Getting the line number or full stack trace on exceptions in a gremlin-groovy script

I have a gremlin-groovy script that traverses a database which is incredibly noisy. 我有一个遍历数据库的gremlin-groovy脚本,这令人难以置信。 There are lots of cases with missing edges or properties. 很多情况下缺少边缘或属性。 When I assume an edge or property exists and it doesn't an exception is thrown I get a very simple output like this: 当我假设边缘或属性存在并且没有引发异常时,我得到一个非常简单的输出,如下所示:

javax.script.ScriptException: java.util.IllegalFormatConversionException: d != java.lang.String

I'd like to make it so when the script encounters a fatal exception, as the one above, it provides a stack dump or at least a line number so I can debug where it happened, similar to how java can print a full stack trace on fatal exceptions. 我想这样做,以便在脚本遇到致命异常时,如上面的脚本所示,它提供堆栈转储或至少一个行号,以便我可以调试发生的位置,类似于java如何打印完整的堆栈跟踪致命的例外。

Any suggestions on how to get a better dump? 关于如何获得更好的转储的任何建议?

I recommend using the Gremlin terminal for this. 我建议为此使用Gremlin终端。

gremlin$ ./gremlin.sh

         \,,,/
         (o o)
-----oOOo-(_)-oOOo-----
gremlin> a bad thing
No such property: bad for class: groovysh_evaluate
Display stack trace? [yN] y
groovy.lang.MissingPropertyException: No such property: bad for class: groovysh_evaluate
    at     org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)

If you don't have this luxury (eg via a REST server), then you may want to place some intelligent 'printlns' in your traversal. 如果您没有这种奢侈感(例如通过REST服务器),则可能需要在遍历中放置一些智能的“ printlns”。

my.long.traversal.sideEffect{println 'I am here'}.is.very.long

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM