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

[native] make sure ParserError's line is zero-indexed #681

Merged
merged 1 commit into from
May 4, 2022

Conversation

zsol
Copy link
Member

@zsol zsol commented May 1, 2022

Summary

The ParserError raised from the peg parser has 0-based line indices, but its __str__ implementation expects it to be 1-based. This causes exceptions while trying to render the ParserError exception.

Fixes #678.

Test Plan

Added tests to verify str() doesn't blow up.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 1, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #681 (e879216) into main (6e0c63a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #681   +/-   ##
=======================================
  Coverage   94.81%   94.81%           
=======================================
  Files         246      246           
  Lines       25607    25608    +1     
=======================================
+ Hits        24279    24280    +1     
  Misses       1328     1328           
Impacted Files Coverage Δ
libcst/_parser/tests/test_parse_errors.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e0c63a...e879216. Read the comment docs.

let kwargs = [
("message", e.to_string().into_py(py)),
("lines", lines.into_py(py)),
("raw_line", line.into_py(py)),
("raw_line", (line + 1).into_py(py)),
("raw_column", col.into_py(py)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is column zero or one based?

Copy link
Contributor

@lpetre lpetre left a comment

Choose a reason for hiding this comment

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

Looks good to me. Please clarify about raw_column

@zsol
Copy link
Member Author

zsol commented May 3, 2022

should be 0-indexed

#: The zero-indexed column as a number of characters from the start of the line
#: where the error occured.
raw_column: int

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IndexError when str(e) for ParserSyntaxError with native parser
4 participants