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

Bugfix: off-by-one error in error message for version parsing #283

Closed
nathanjmcdougall opened this issue Jul 24, 2024 · 2 comments · Fixed by #286
Closed

Bugfix: off-by-one error in error message for version parsing #283

nathanjmcdougall opened this issue Jul 24, 2024 · 2 comments · Fixed by #286
Labels
.bug Something isn't working

Comments

@nathanjmcdougall
Copy link
Contributor

Another nitpicky issue with these error messages:

def from_string(cls, version: str) -> "Version":
parts = version.split("-")
if len(parts) != 2:
raise PinsVersionError(
"version string can only have 1 '-', but contains %s" % len(parts)
)

If there is a malformed version spam-eggs-spam, this will emit
version string can only have 1 '-', but contains 3
Which is misleading, since there are only 2 hyphens, not 3.

While changing this, I think I'd prefer to use try-except ValueError around the unpacking of parts rather than have a dedicated != 2 check so that could be changed too.

@isabelizimm
Copy link
Collaborator

Ah, the off by one value error I can't unsee 🙈 I think the !=2 is an okay check, is there a particular reason to make the swap to a ValueError?

@isabelizimm isabelizimm added .enhancement New feature or request .bug Something isn't working and removed .enhancement New feature or request labels Jul 25, 2024
@nathanjmcdougall
Copy link
Contributor Author

nathanjmcdougall commented Jul 25, 2024

It just avoids having to write an explicit check (so I think it makes clearer the connection between the check and the unpacking step that follows), but really it's a style/preference thing so I'll leave it be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants