Unhandled error on javascript with invalid syntax
Closed this issue · 6 comments
aredridel commented
In a repository with a bad javascript file:
events.js:72
throw er; // Unhandled 'error' event
^
Error: Line 1: Unexpected token ILLEGAL
at throwError (/usr/local/lib/node_modules/codepainter/node_modules/esprima/esprima.js:1828:21)
at scanPunctuator (/usr/local/lib/node_modules/codepainter/node_modules/esprima/esprima.js:804:9)
at advance (/usr/local/lib/node_modules/codepainter/node_modules/esprima/esprima.js:1299:16)
at collectToken (/usr/local/lib/node_modules/codepainter/node_modules/esprima/esprima.js:1314:17)
at peek (/usr/local/lib/node_modules/codepainter/node_modules/esprima/esprima.js:1357:61)
at parseProgram (/usr/local/lib/node_modules/codepainter/node_modules/esprima/esprima.js:3524:9)
at Object.parse (/usr/local/lib/node_modules/codepainter/node_modules/esprima/esprima.js:3778:23)
at Tokenizer.end (/usr/local/lib/node_modules/codepainter/lib/Tokenizer.js:26:24)
at ReadStream.onend (_stream_readable.js:483:10)
at ReadStream.g (events.js:180:16)
at ReadStream.EventEmitter.emit (events.js:117:20)
atroche commented
I'm getting something similar:
/C/z/z/lib git:master ❯❯❯ codepaint infer app.js ⏎ ✭
events.js:72
throw er; // Unhandled 'error' event
^
Error: Line 16: Unexpected reserved word
at throwError (/opt/boxen/nodenv/versions/v0.10.21/lib/node_modules/codepainter/node_modules/esprima/esprima.js:1831:21)
at throwUnexpected (/opt/boxen/nodenv/versions/v0.10.21/lib/node_modules/codepainter/node_modules/esprima/esprima.js:1880:17)
at parsePrimaryExpression (/opt/boxen/nodenv/versions/v0.10.21/lib/node_modules/codepainter/node_modules/esprima/esprima.js:2180:17)
at parseLeftHandSideExpressionAllowCall (/opt/boxen/nodenv/versions/v0.10.21/lib/node_modules/codepainter/node_modules/esprima/esprima.js:2275:61)
at parsePostfixExpression (/opt/boxen/nodenv/versions/v0.10.21/lib/node_modules/codepainter/node_modules/esprima/esprima.js:2325:16)
at parseUnaryExpression (/opt/boxen/nodenv/versions/v0.10.21/lib/node_modules/codepainter/node_modules/esprima/esprima.js:2384:20)
at parseBinaryExpression (/opt/boxen/nodenv/versions/v0.10.21/lib/node_modules/codepainter/node_modules/esprima/esprima.js:2473:16)
at parseConditionalE%
Any ideas?
jednano commented
It means your JavaScript files aren't valid JavaScript. You need to check the files for valid syntax. If it doesn't parse on Esprima's parser here it won't parse in CodePainter either.
atroche commented
Thanks for the quick response! It's because we were using the import
syntax from ES6. Is there anyway of making it show a line number of where the parsing error is? Would've made this a lot easier to debug.
aredridel commented
Yeah, that's really where this falls down -- I don't think supporting invalid code is that useful, but not failing gracelessly and making it hard to debug would be awesome.
jednano commented
aredridel commented
Oh, winning!