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

Throw more meaningful error if .babelrc is not a valid JSON file #9052

Merged
merged 1 commit into from
Sep 7, 2017

Conversation

klaussner
Copy link
Contributor

Just a small improvement of the error that is thrown if a .babelrc file doesn't contain valid JSON. For example, the error message will be

.babelrc is not a valid JSON file: Unexpected token }

instead of

Unexpected token }

for the invalid .babelrc file

{
  "plugins":
}

Resolves #8792

JSON.parse(inputFile.readAndWatchFile(babelrcPath));
} catch (e) {
if (e instanceof SyntaxError) {
throw new Error(".babelrc is not a valid JSON file: " + e.message);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this gets rid of the stacktrace in e as it's not passed into the new error being thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure? The stack trace should be similar because the error is thrown at (almost) the same source location as before.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking it's loosing the stack trace from the command that threw the error we're catching.

Copy link
Contributor

@benjamn benjamn Sep 6, 2017

Choose a reason for hiding this comment

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

What about just

e.message = ".babelrc is not a valid JSON file: " + e.message;
throw e;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good!

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.

None yet

3 participants