Repository navigation
fix: decode remote command output before formatting errors - #195
Conversation
On Python 2, fabric returns remote command output as bytes. Interpolating it into a unicode message in _sudo_checked implicitly decoded it as ASCII, raising UnicodeDecodeError that hid the real remote failure (e.g. git apply conflict details containing non-ASCII context lines). Decode remote output as UTF-8 via as_text() in _sudo_checked, the rejected hunks report, and GitApplier.catch_result.
|
Això ho he provat jo amb una PR que em donava problemes i amb això es soluciona |
giscebot
left a comment
There was a problem hiding this comment.
Correct fix and appropriately scoped. Converting Fabric output through the existing as_text() boundary before Unicode formatting preserves the original remote diagnostic on Python 2, while keeping Python 3 behavior and providing the established replacement fallback for malformed bytes. The same normalization is consistently applied to _sudo_checked, rejected-hunk reporting, and GitApplier.catch_result.
Checked the complete diff and error propagation paths. Locally, all 58 tests pass on Python 2.7 and Python 3.11. I also ran the new regression test against master with only the test overlaid: it fails with the reproduced ASCII UnicodeDecodeError, proving that the test detects the bug. Both GitHub Actions jobs pass.
|
Post-merge follow-up: PR #195 is merged as |
Summary
_AttributeString/str). Interpolating it into a unicode message in_sudo_checkedimplicitly decoded it as ASCII, raisingUnicodeDecodeError('ascii' codec can't decode byte 0xc3...) that hid the real remote failure — e.g.git apply --rejectconflicts whose context lines contain non-ASCII text (Catalan/Spanish accents in the codebase).as_text()helper in_sudo_checked, the rejected-hunks report, andGitApplier.catch_result(replacing the PY2/PY3 decode branches; also addsreplacefallback for non-UTF-8 bytes).test_utf8_remote_output_is_decoded_before_formattingmocks the remote result as bytes, matching what fabric actually returns on PY2 (the existing unicode test used atext_typemock, which is why this crash escaped).Test plan
python -m unittest discover -s testson Python 2.7 — 58/58 OK (new test fails before the fix with the exact'ascii' codec can't decode byte 0xc3symptom)python3 -m py_compileon changed files