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

Remove sub-expressions from parsing error #396

Merged
merged 3 commits into from
Oct 22, 2017

Conversation

andrea-prearo
Copy link
Contributor

This PR skips printing sub-expressions in the error message.

This should avoid situations where the error message contains an AST with unreadable characters, as shown here.

unreadable-chars

@andrea-prearo
Copy link
Contributor Author

@BurntSushi This PR is a follow up to our recent discussion on regex-syntax error messages.
It is intended to be a temporary workaround until we can have a better regex parser/pretty printer.

@@ -1589,8 +1589,7 @@ impl fmt::Display for ErrorKind {
RepeaterExpectsExpr =>
write!(f, "Missing expression for repetition operator."),
RepeaterUnexpectedExpr(ref 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.

I didn't remove the unused variable e because I assumed it can be put back into the error message again once the issues with the AST pretty printing are solved. But, if it makes sense, I can modify the code further to convert RepeaterUnexpectedExpr(Expr) to RepeaterUnexpectedExpr and get rid of the unused variable.

Copy link
Member

Choose a reason for hiding this comment

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

@andrea-prearo Right, but this produces a compile warning, which causes the build to fail. You definitely don't want to change the error type itself, but using RepeaterUnexpectedExpr(_) is the right thing to do here.

There are other errors that try to print sub-expressions. Could you fix those too? e.g., InvalidClassEscape and maybe more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BurntSushi I just noticed that warnings are treated as errors by looking at the CI log. I'll fix that by using RepeaterUnexpectedExpr(_) as you suggested. I'll also work on fixing other sub-expressions.

@@ -1589,8 +1589,7 @@ impl fmt::Display for ErrorKind {
RepeaterExpectsExpr =>
write!(f, "Missing expression for repetition operator."),
RepeaterUnexpectedExpr(ref e) =>
Copy link
Member

Choose a reason for hiding this comment

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

@andrea-prearo Right, but this produces a compile warning, which causes the build to fail. You definitely don't want to change the error type itself, but using RepeaterUnexpectedExpr(_) is the right thing to do here.

There are other errors that try to print sub-expressions. Could you fix those too? e.g., InvalidClassEscape and maybe more.

@andrea-prearo
Copy link
Contributor Author

I went through all the errors and didn't see other instances that try to print out sub-expressions.

@andrea-prearo
Copy link
Contributor Author

The build is failing on beta and nightly for reasons unrelated to these changes.

screen shot 2017-08-31 at 10 50 22 am

screen shot 2017-08-31 at 11 27 46 am

@BurntSushi
Copy link
Member

@andrea-prearo Right, yeah, I'll submit a PR when I get a chance fixing that.

@andrea-prearo
Copy link
Contributor Author

@BurntSushi Sounds good. Thanks!

@BurntSushi
Copy link
Member

@andrea-prearo Could you rebase this on master? That should hopefully get CI passing!

@andrea-prearo
Copy link
Contributor Author

andrea-prearo commented Sep 27, 2017

@BurntSushi I had issues with the rebase, so I had to do some clean up. But tests are passing now!

@BurntSushi
Copy link
Member

@andrea-prearo Thanks! @bors r+

@bors
Copy link
Contributor

bors commented Oct 22, 2017

📌 Commit ba5a3df has been approved by BurntSushi

@bors
Copy link
Contributor

bors commented Oct 22, 2017

⌛ Testing commit ba5a3df with merge 72cee88...

bors added a commit that referenced this pull request Oct 22, 2017
…urntSushi

Remove sub-expressions from parsing error

This PR skips printing sub-expressions in the error message.

This should avoid situations where the error message contains an AST with unreadable characters, as shown [here](BurntSushi/ripgrep#395).

<img width="1030" alt="unreadable-chars" src="https://user-images.githubusercontent.com/12599697/29924193-02147d0c-8e11-11e7-8b36-a97b63f802b4.png">
@bors
Copy link
Contributor

bors commented Oct 22, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: BurntSushi
Pushing 72cee88 to master...

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.

3 participants