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

Improve ParseIndexError::InvalidCharacter error #94

Merged
merged 5 commits into from
Oct 29, 2024

Conversation

asmello
Copy link
Collaborator

@asmello asmello commented Oct 21, 2024

In #80 I introduced a new error variant to capture cases where the array index starts with + (which is valid for usize representations in Rust, but not valid for array indices per RFC 6901).

As I noted here, keeping a collection of invalid characters in the error variant is overkill, since the accepted domain of usize::parse is very unlikely to evolve, as that'd be a breaking change in std. According to the docs + is the only accepted non-digit character, so we don't need to expect any others.

I'm not specialising the variant name for + though to leave some room for later adopting a different parser that has different domain (unlikely as that is) or in the off chance std does change this API. The error message changing isn't a hard break, if we ever need to update it in the future, so I'm keeping it more specific to make it more useful.

@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 88.13559% with 7 lines in your changes missing coverage. Please review.

Project coverage is 99.0%. Comparing base (c694765) to head (52f435a).

Files with missing lines Patch % Lines
src/index.rs 84.7% 7 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/assign.rs 99.6% <100.0%> (+<0.1%) ⬆️
src/index.rs 96.5% <84.7%> (-3.5%) ⬇️

... and 1 file with indirect coverage changes

@asmello
Copy link
Collaborator Author

asmello commented Oct 21, 2024

I wonder if we should also make the validation more specific (to reduce the chance of the error message lying to the user), at the risk of accepting an invalid input we didn't expect to pass the usize::parse parsing. Probably overthinking it.

src/index.rs Show resolved Hide resolved
@asmello asmello changed the title simplify error variant Improve ParseIndexError::InvalidCharacter error Oct 21, 2024
@asmello asmello requested a review from chanced October 21, 2024 21:24
@chanced chanced merged commit bf648a4 into chanced:main Oct 29, 2024
19 of 20 checks passed
chanced pushed a commit that referenced this pull request Nov 8, 2024
* improves ParseIndexError::InvalidCharacter
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