Properly decode API errors from UTF-8
Review Request #10697 — Created Sept. 6, 2019 and submitted
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 usingunicode_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.
Summary | ID | Author |
---|---|---|
a098a9b4bdb8284154ddb245796d10d0fac6f1ee | Barret Rennie |
Description | From | Last Updated |
---|---|---|
Wrapping in Testing Done is wrong. Make sure you're not wrapping in the middle of a literal. |
chipx86 | |
This should land on release-1.0.x, rather than mater, I think? |
chipx86 | |
Typo in testing done: verisons -> versions. |
david | |
In "Testing Done", "Confirmed the following hold true" is still pretty weird phrasing. How about just "Confirmed the following on … |
david | |
Can you give this a docstring while here? |
chipx86 | |
You can use rbtools.utils.encoding.force_unicode() for this. |
chipx86 | |
Okay, higher-level. The newlines that we have in here seem to be in the wrong place. We're joining the entries … |
chipx86 | |
Also, no u prefix. |
chipx86 | |
F821 undefined name 'msg' |
reviewbot |
-
-
-
-
-
-
Okay, higher-level.
The newlines that we have in here seem to be in the wrong place. We're joining the entries together with a newline when raising
CommandError
. If we're aiming to create blank lines between things, which I think is the purpose, let's strip away\n
from these strings and just join with\n\n
instead.We also should probably not be wrapping for error code 219. Wrapping to the terminal width is fine if we're going to do that, we should do it in the handler for
CommandError
(which doesn't need to happen in this change, but let's fix the strings anyway). -
- 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. ~ Confirmed the following hold true 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.
- With this entire patch stack (/r/10685, /r/10695, and /r/10696),
- Commits:
-
Summary ID Author b753f871393357af40be95e3341d5a8661ba7f24 Barret Rennie 943cd2af8af400d7ca9cdf44ac47d13c69b6f3db Barret Rennie - Diff:
-
Revision 2 (+40 -24)
- Commits:
-
Summary ID Author 943cd2af8af400d7ca9cdf44ac47d13c69b6f3db Barret Rennie a098a9b4bdb8284154ddb245796d10d0fac6f1ee Barret Rennie - Diff:
-
Revision 3 (+40 -24)
Checks run (2 succeeded)
- Testing Done:
-
~ Confirmed the following hold true on Python verisons 2.7, 3.5, 3.6, and
~ Confirmed the on Python versions 2.7, 3.5, 3.6, and 3.7:
- 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.
- With this entire patch stack (/r/10685, /r/10695, and /r/10696),