Regex for JavaScript source

纵饮孤独 提交于 2020-01-06 08:01:12

问题


XPages application fails with following stack trace:

com.ibm.jscript.InterpretException: Script interpreter error, line=30, col=43: 'component' is null
at com.ibm.jscript.ASTTree.ASTMember.interpret(ASTMember.java:153)
at com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:88)
at com.ibm.jscript.ASTTree.ASTBlock.interpret(ASTBlock.java:100)
at com.ibm.jscript.ASTTree.ASTIf.interpret(ASTIf.java:85)
at com.ibm.jscript.ASTTree.ASTBlock.interpret(ASTBlock.java:100)
at com.ibm.jscript.ASTTree.ASTIf.interpret(ASTIf.java:85)
at com.ibm.jscript.ASTTree.ASTBlock.interpret(ASTBlock.java:100)
at com.ibm.jscript.ASTTree.ASTTry.interpret(ASTTry.java:109)
at com.ibm.jscript.ASTTree.ASTIf.interpret(ASTIf.java:85)
at com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119)
at com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139)

From this I know, that there is problem with variable "component" nested inside hierarchy of blocks: if -> try -> { -> if -> { -> if -> { -> method call with invalid argument.

I don't know what to look for exactly, search for "component" yields too many results.

What regex should I use to find the right spot based on code hierarchy?


回答1:


In this case I see a good chance that you have not put all your SSJS code into try/catch blocks. The bad news: searching the cause of this error is extremely cumbersome as close to all SSJS blocks may be the root cause of this error.

For that reason I placed my own rule (and ignore it every now and then) to put EVERY SSJS block into a try/catch like this:

try {
    // ... do fancy stuff here
} catch (e) {
    print(e.toString());
}

The toString() call is used for some special cases where the error object appears to no automatically convert into an object that can be handled by the print method.

If it is the case, you have not put all SSJS blocks into a try/catch, this is exactly the right time to do so and keep that coding pattern for the future. It really helps every now and then ;-)




回答2:


Instead of printStackTrace and toString() , you could just say print(e), which will output only the error message(should be the same as e.message). The error object if passed to a java routine, you could get the error line.

variable "component" nested inside hierarchy of blocks ==> We have made this working without issues.



来源:https://stackoverflow.com/questions/13516712/regex-for-javascript-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!