Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch babel parse errors #198

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

michaelfaith
Copy link
Contributor

This change updates the plugin to catch babel parsing errors, so that we can give prettier a chance to throw. We're still writing an error to console, so that in the event that prettier doesn't end up throwing, we're still indicating that the import sorting failed.

screenshot of new behavior

Closes #197

const ast = babelParser(code, parserOptions);
let ast;
try {
ast = babelParser(code, parserOptions);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said in the original issue that it was babel.traverse that was throwing, but I mispoke; it was actually the parse that happens first. So, I only wrapped the parse itself.

fbartho

This comment was marked as outdated.

This change updates the plugin to catch babel parsing errors, so that we can give prettier a chance to throw.  We're still writing an error to console, so that in the event that prettier doesn't end up throwing, we're still indicating that the import sorting failed.
@michaelfaith michaelfaith force-pushed the fix/catch-babel-parse-errors branch from 939e461 to 26a54f0 Compare January 12, 2025 23:52
@michaelfaith michaelfaith requested a review from fbartho January 12, 2025 23:52
Copy link
Collaborator

@fbartho fbartho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IanVS will have to do the next steps, but this looks good to me!

thanks again!

IanVS and others added 2 commits January 13, 2025 09:07
Co-authored-by: Frederic Barthelemy <github@fbartho.com>
@IanVS
Copy link
Owner

IanVS commented Jan 13, 2025

Thanks a ton, @michaelfaith, this will be very helpful.

@IanVS IanVS merged commit e62e159 into IanVS:main Jan 13, 2025
8 checks passed
@michaelfaith michaelfaith deleted the fix/catch-babel-parse-errors branch January 16, 2025 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugin throws less helpful errors when code has a SyntaxError
3 participants