Skip to content

Give better struct errors #1320

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

Merged
merged 1 commit into from
Dec 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions kafka/protocol/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
def _pack(f, value):
try:
return pack(f, value)
except error:
raise ValueError(error)
except error as e:
raise ValueError("Error encountered when attempting to convert value: "
"{} to struct format: '{}', hit error: {}"
Copy link
Collaborator

@tvoinarovskyi tvoinarovskyi Dec 8, 2017

Choose a reason for hiding this comment

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

Maybe {!r} for value just in case str is overridden.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to do this earlier, changed in #1373

.format(value, f, e))


def _unpack(f, data):
try:
(value,) = unpack(f, data)
return value
except error:
raise ValueError(error)
except error as e:
raise ValueError("Error encountered when attempting to convert value: "
"{} to struct format: '{}', hit error: {}"
.format(value, f, e))


class Int8(AbstractType):
Expand Down