JsChecker crashes on invalid template literal (JsCompiler shows error msg)
mbrukman opened this issue · 1 comments
Similar to issue #496, I am running into issues where JsChecker is crashing with an internal error, while JsCompiler reports a meaningful error message.
Here's a relevant excerpt from my WORKSPACE
:
git_repository(
name = "io_bazel_rules_closure",
remote = "https://github.com/bazelbuild/rules_closure.git",
commit = "62746bdd1087c1198a81143e7d8ef3d144a43c0f",
)
Here's a minified example of a problematic file:
$ cat tpl.js
var a = `${<b>text</b>}`;
JsChecker fails on this file:
$ ../../bazel-out/host/bin/external/io_bazel_rules_closure/java/io/bazel/rules/closure/ClosureWorker \
JsChecker --src tpl.js
ERROR: Program threw uncaught exception with args: JsChecker --src tpl.js
java.lang.RuntimeException: Exception parsing "tpl.js"
at com.google.javascript.jscomp.parsing.ParserRunner.parse(ParserRunner.java:155)
at com.google.javascript.jscomp.JsAst.parse(JsAst.java:152)
at com.google.javascript.jscomp.JsAst.getAstRoot(JsAst.java:55)
at com.google.javascript.jscomp.CompilerInput.getAstRoot(CompilerInput.java:133)
at com.google.javascript.jscomp.Compiler.parseInputs(Compiler.java:1714)
at com.google.javascript.jscomp.Compiler.parseForCompilationInternal(Compiler.java:937)
at com.google.javascript.jscomp.Compiler.lambda$parseForCompilation$4(Compiler.java:920)
at com.google.javascript.jscomp.CompilerExecutor.runInCompilerThread(CompilerExecutor.java:129)
at com.google.javascript.jscomp.Compiler.runInCompilerThread(Compiler.java:824)
at com.google.javascript.jscomp.Compiler.parseForCompilation(Compiler.java:918)
at com.google.javascript.jscomp.Compiler.compile(Compiler.java:674)
at com.google.javascript.jscomp.JsChecker.run(JsChecker.java:255)
at com.google.javascript.jscomp.JsChecker.access$300(JsChecker.java:63)
at com.google.javascript.jscomp.JsChecker$Program.apply(JsChecker.java:354)
at io.bazel.rules.closure.worker.LegacyAspect.run(LegacyAspect.java:38)
at io.bazel.rules.closure.ClosureWorker.run(ClosureWorker.java:69)
at io.bazel.rules.closure.worker.PersistentWorker.runProgram(PersistentWorker.java:109)
at io.bazel.rules.closure.worker.PersistentWorker.run(PersistentWorker.java:88)
at io.bazel.rules.closure.ClosureWorker.main(ClosureWorker.java:111)
Caused by: java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 6
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
at java.base/java.lang.String.substring(String.java:1874)
at com.google.javascript.jscomp.parsing.IRFactory.normalizeRegex(IRFactory.java:3538)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.processRegExpLiteral(IRFactory.java:2229)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.processLiteralExpression(IRFactory.java:3260)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.process(IRFactory.java:3353)
at com.google.javascript.jscomp.parsing.IRFactory.transform(IRFactory.java:833)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.processBinaryExpressionHelper(IRFactory.java:1835)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.processBinaryExpression(IRFactory.java:1811)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.process(IRFactory.java:3271)
at com.google.javascript.jscomp.parsing.IRFactory.transform(IRFactory.java:833)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.processExpressionStatement(IRFactory.java:1451)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.process(IRFactory.java:3303)
at com.google.javascript.jscomp.parsing.IRFactory.transform(IRFactory.java:833)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.processAstRoot(IRFactory.java:1303)
at com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.process(IRFactory.java:3351)
at com.google.javascript.jscomp.parsing.IRFactory.transformTree(IRFactory.java:344)
at com.google.javascript.jscomp.parsing.ParserRunner.parse(ParserRunner.java:144)
... 18 more
whereas JsCompiler reports an error message:
$ java -jar closure-compiler-v20200719.jar --js tpl.js
tpl.js:1: ERROR - [JSC_PARSE_ERROR] Parse error. primary expression expected
1| var a = `${<b>text</b>}`;
^
1 error(s), 0 warning(s)
If JsChecker is wrapping JsCompiler, would it be possible for it to emit the same error message as JsCompiler would in this situation, rather than crashing? A crashing compiler doesn't help with fixing the syntax error, and it would be great to be able to just run bazel build
and get the useful error message without having to manually run JsCompiler to see what's wrong.
FWIW, I was thinking that maybe this was fixed in a recent version of JsCompiler while JsChecker is using an old one; however, that does not appear to be the case. The commit of this repo I'm using (62746bd) includes JsCompiler version v20200614 (as of commit d69cb55), but the output from JsCompiler is the same at that version as well:
$ java -jar closure-compiler-v20200614.jar --js tpl.js
tpl.js:1: ERROR - [JSC_PARSE_ERROR] Parse error. primary expression expected
1| var a = `${<b>text</b>}`;
^
1 error(s), 0 warning(s)
This is very likely fixed now. Please re-open if not.