Display implementation for Uuid::from_bytes / Parse::InvalidLength is incorrect #281
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid#281
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Describe the bug
When trying to parse Uuid using
Uuid::from_bytes, an invalid byte array of size 32 or 36 gives you an incorrect Display string:Invalid length; expecting 32 or 36 chars, found 36This is because the code is checking for length 16: https://docs.rs/uuid/0.6.5/src/uuid/lib.rs.html#711-720, and the error message is outputting
adapter:: UUID_HYPHENATED_LENGTHandadapter:: UUID_SIMPLE_LENGTHwhich are 36 and 32: https://github.com/uuid-rs/uuid/blob/master/src/adapter.rs#L19.To Reproduce
Steps to reproduce the behavior:
Uuid::from_bytes.Expected behavior
A correct error message should appear, not sure what the ideal error message for this is.
Screenshots
N/A
Specifications (please complete the following information):
Additional context
N/A
Other
N/A
hi @DarrenTsung thanks for reporting this.
I think the main issue I see here is that
ParseErroris primarily designed around parsing strings. However, our overall design expected bytes.The way I think we can fix this is by leaving the current error message as is. I cannot change the message without making the error confusing for people using string parsing.
Instead in
0.7.0(which already has a refactor for the error type planned, see #276), I can have 2 invalid length variants, one for string and one for bytes.