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

Add location information to parsing errors #7314

Merged
merged 1 commit into from Feb 4, 2018

Conversation

@kaicataldo
Copy link
Member

kaicataldo commented Feb 2, 2018

Q                       A
Fixed Issues? refs babel/babel-eslint#573 (comment)
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR
Any Dependency Changes? No
License MIT

As discussed in Slack, this PR retains location information for errors thrown by the parser and adds error codes so that the consumer can distinguish between errors easily.

A few questions I have:

  1. Did I miss any spots?
  2. Should we be exposing these error codes as constants that a consumer can import so they don't have to care about Babel changing these strings? With only two errors codes, maybe this isn't necessary. They're also shared across packages, so I'm not sure how the team would want to go about that.
  3. I didn't update any tests - should I have?
@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Feb 2, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6791/

@@ -110,6 +109,7 @@ function parser(pluginPasses, options, code) {
err.message =
`${options.filename || "unknown"}: ${err.message}\n\n` + codeFrame;
}
err.code = "BABEL_PARSE_ERROR";

This comment has been minimized.

Copy link
@hzoo

hzoo Feb 2, 2018

Member

I don't know if this is the first time we started doing this but are we going to have some kind of convention for this, docs? Or is this just a one-off @loganfsmyth

This comment has been minimized.

Copy link
@loganfsmyth

loganfsmyth Feb 2, 2018

Member

I think error codes are good. Probably in the long run anywhere we throw an error in babel-core should have its own code. Even better would be if Babylon already included a code and this code checked

if (err.code === "BABYLON_PARSE_ERROR")

then Babel wrapped it somehow, but eh :)

This comment has been minimized.

Copy link
@hzoo

hzoo Feb 2, 2018

Member

Ok yeah ^ was what I was thinking. maybe @kaicataldo can you make an issue about that? I think a task could be to look through all the places we throw and to think about if we want to make an errors file kind of deal, etc. And I think we would want this to be consistent moving forward and to be more maintainable?

This comment has been minimized.

Copy link
@kaicataldo

kaicataldo Feb 2, 2018

Author Member

Would be great to make this consistent! Would this be just for Babylon and babel-core? Or all packages?

This comment has been minimized.

Copy link
@hzoo

hzoo Feb 2, 2018

Member

It's funny also because I'm reminded we have a package called babel-messages that we sometimes use?

err.message += "\n" + codeFrameColumns(code, { start: loc });
err.code = "BABEL_PARSE_ERROR";

This comment has been minimized.

Copy link
@loganfsmyth

loganfsmyth Feb 2, 2018

Member

Since this isn't the user's own code failing parsing, I'd vote for this having a different code like BABEL_TEMPLATE_PARSE_ERROR or something.

@kaicataldo kaicataldo force-pushed the kaicataldo:parser-error-loc branch from 2337b7c to 0056fdb Feb 2, 2018
@kaicataldo

This comment has been minimized.

Copy link
Member Author

kaicataldo commented Feb 2, 2018

Updated!

@hzoo
hzoo approved these changes Feb 4, 2018
@existentialism existentialism merged commit 7234442 into babel:master Feb 4, 2018
4 checks passed
4 checks passed
babel/repl REPL preview is available
Details
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 87.4% (target 80%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
kaicataldo added a commit that referenced this pull request Feb 5, 2018
This reverts commit 7234442.
@kaicataldo kaicataldo deleted the kaicataldo:parser-error-loc branch Feb 5, 2018
@kaicataldo

This comment has been minimized.

Copy link
Member Author

kaicataldo commented Feb 5, 2018

Whoops - was trying to delete the branch, not revert the merge!

aminmarashi-binary added a commit to aminmarashi-binary/babel that referenced this pull request Mar 17, 2018
@lock lock bot added the outdated label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants
You can’t perform that action at this time.