i18n-extract icon indicating copy to clipboard operation
i18n-extract copied to clipboard

Filename missing when SyntaxError thrown

Open zbycz opened this issue 6 years ago • 2 comments

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

zbycz avatar Nov 29 '18 16:11 zbycz

What do you think of the suggested solution. Should I create a PR?

zbycz avatar Dec 14 '18 09:12 zbycz

@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.

oliviertassinari avatar Dec 14 '18 10:12 oliviertassinari