Properly decode API errors from UTF-8

Review Request #10697 — Created Sept. 6, 2019 and submitted — Latest diff uploaded

Information

RBTools
release-1.0.x

Reviewers

When we received an error message from the Review Board API, if we
didn't have a pre-generated string for that error code locally we would
include the error body verbatim. We did this by attempting to cast it to
a string and encode it to utf-8, but that only works on Python 2 where
str is actually bytes. On Python 3, an error is raised becuase you are
not allowed to decode a bytes object into text without a codec.

Instead, we now return text from the API errors when calling str(e) on
them, instead of returning their body verbatim.

While I was here, I also removed a bunch of unnecessary unicode
literals. We are using unicode_literals everywhere so they were
redundant.

Confirmed the on Python versions 2.7, 3.5, 3.6, and 3.7:

  • With this entire patch stack (/r/10685, /r/10695, and /r/10696),
    rbt post is able to create review requests with commit history.

Diff Revision 1

This is not the most recent revision of the diff. The latest diff is revision 3. See what's changed.

orig
1
2
3

Commits

First Last Summary ID Author
Properly decode API errors from UTF-8
When we received an error message from the Review Board API, if we didn't have a pre-generated string for that error code locally we would include the error body verbatim. We did this by attempting to cast it to a string and encode it to utf-8, but that only works on Python 2 where str is actually bytes. On Python 3, an error is raised becuase you are not allowed to decode a bytes object into text without a codec. Instead, we now return text from the API errors when calling `str(e)` on them, instead of returning their body verbatim. While I was here, I also removed a bunch of unnecessary unicode literals. We are using `unicode_literals` everywhere so they were redundant. Testing done: Confirmed the following hold on Python verisons 2.7, 3.5, 3.6, and 3.7: - With this entire patch stack (/r/10685, /r/10695, and /r/10696), `rbt post` is able to create review requests with commit history.
b753f871393357af40be95e3341d5a8661ba7f24 Barret Rennie
rbtools/api/errors.py
rbtools/commands/post.py
Loading...