i18n-extract
i18n-extract copied to clipboard
Filename missing when SyntaxError thrown
I extract from .flow.js files, and babel parses these quite well. But if I make a syntax error, the output isnt very helpful (see below). Could we catch the SyntaxError here and perhaps re-throw it with a filename?
/node_modules/i18n-extract/node_modules/babylon/lib/index.js:788
throw err;
^
SyntaxError: Unexpected token, expected "," (27:17)
at _class.raise (.../node_modules/i18n-extract/node_modules/babylon/lib/index.js:776:15)
...
at _class.parse (.../node_modules/i18n-extract/node_modules/babylon/lib/index.js:5304:17)
at parse (.../node_modules/i18n-extract/node_modules/babylon/lib/index.js:10095:38)
at extractFromCode (.../node_modules/i18n-extract/lib/extractFromCode.js:79:32)
at .../node_modules/i18n-extract/lib/extractFromFiles.js:30:54
at Array.forEach (<anonymous>)
at extractFromFiles (.../node_modules/i18n-extract/lib/extractFromFiles.js:27:10)
at bootstrap_node.js:609:3
What do you think of the suggested solution. Should I create a PR?
@zbycz You are right to report this problem. It's important to have meaningful error messages. It can save people a lot of time.
I'm happy with the solution that changes extractFromCode()
to catch the error, log in the console the source filename and rethrow the original error.