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

marshal: Add an error when UUID has wrong length #890

Merged
merged 3 commits into from
Apr 9, 2017
Merged

marshal: Add an error when UUID has wrong length #890

merged 3 commits into from
Apr 9, 2017

Conversation

leighmcculloch
Copy link
Contributor

What

Add a descriptive error when a UUID is marshaled or unmarshaled and the length of the []byte is not exactly 16 bytes long.

Example

can not marshal []byte 6 bytes long into timeuuid, must be exactly 16 bytes long

Why

In cases where UUID []byte was not the correct length the generic can not marshal %T into %s error was being returned. The error was misleading because it gave the impression the root cause was the type of the data and not it's length. Additionally the %T formatter for a []byte prints out []uint8 which was even more confusing.

Notes

This PR contains three commits. It's easier to digest the change if you review them separately as the first refactors the tests to support expectations on the error itself.

Ref

Fixes #868

What
===
Add explicit expectations to exactly what error is returned in
test cases where the marshal and unmarshal results in an error.

Why
===
In cases where an unmarshal fails the presence of an error was expected
but not what error was returned. Marshal is not tested for the cases
where it fails in the table tests. Both of these are needed to add
more tests that test for new errors being returned.
What
===
Add a descriptive error when a UUID is attempted to be marshaled or
unmarshaled and the length of the []byte is not exactly 16 bytes long.

Example
===

```
can not marshal []byte 6 bytes long into timeuuid, must be exactly 16 bytes long
```

Why
===
In cases where UUID []byte was not the correct length the generic `can
not marshal %T into %s` error was being returned. The error was
misleading because it gave the impression the root cause was the type of
the data and not it's length. Additionally the `%T` formatter for a
`[]byte` prints out `[]uint8` which was even more confusing.
What
===
Add `Leigh McCulloch` to AUTHORS.

Why
===
As part of his first contribution.
},
{
NativeType{proto: 2, typ: TypeVarint},
[]byte(nil),
nil,
nil,
UnmarshalError("can not unmarshal into non-pointer <nil>"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Zariel: 👋 Aside to the main issue being addressed in this PR it looks like the Marshal and Unmarshal functions are not entire symmetrical. The []byte here can be marshaled but not unmarshaled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I guess the asymmetry here doesn't matter, since you wouldn't Unmarshal into nil.

@Zariel
Copy link
Contributor

Zariel commented Apr 9, 2017

Thanks very much for the contribution!

@Zariel Zariel merged commit 329465a into apache:master Apr 9, 2017
@leighmcculloch leighmcculloch deleted the issue-868 branch April 9, 2017 21:55
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.

2 participants