Skip to content

fix: decode remote command output before formatting errors - #195

Merged
ecarreras merged 1 commit into
masterfrom
fix/py2-remote-output-decode
Oct 9, 2026
Merged

ecarreras merged 1 commit into
masterfrom
fix/py2-remote-output-decode

Conversation

@abaena-gisce

Copy link
Copy Markdown
Member

Summary

  • On Python 2, fabric returns remote command output as bytes (_AttributeString/str). Interpolating it into a unicode message in _sudo_checked implicitly decoded it as ASCII, raising UnicodeDecodeError ('ascii' codec can't decode byte 0xc3...) that hid the real remote failure — e.g. git apply --reject conflicts whose context lines contain non-ASCII text (Catalan/Spanish accents in the codebase).
  • Decode remote output as UTF-8 via the existing as_text() helper in _sudo_checked, the rejected-hunks report, and GitApplier.catch_result (replacing the PY2/PY3 decode branches; also adds replace fallback for non-UTF-8 bytes).
  • New test test_utf8_remote_output_is_decoded_before_formatting mocks the remote result as bytes, matching what fabric actually returns on PY2 (the existing unicode test used a text_type mock, which is why this crash escaped).

Test plan

  • python -m unittest discover -s tests on Python 2.7 — 58/58 OK (new test fails before the fix with the exact 'ascii' codec can't decode byte 0xc3 symptom)
  • python3 -m py_compile on changed files
  • CI Python 3.11 job

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.
@abaena-gisce

Copy link
Copy Markdown
Member Author

Això ho he provat jo amb una PR que em donava problemes i amb això es soluciona

@ecarreras
ecarreras requested a review from giscebot October 8, 2026 21:04

@giscebot giscebot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@ecarreras ecarreras added the patch Patch auto version V_._.X label Oct 9, 2026
@ecarreras
ecarreras merged commit fac1f00 into master Oct 9, 2026
2 checks passed
@ecarreras
ecarreras deleted the fix/py2-remote-output-decode branch October 9, 2026 08:34
@giscebot

giscebot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Post-merge follow-up: PR #195 is merged as fac1f00f2b0831e85a050832bafd43fad2fe9947; both Python 2.7 and Python 3.11 checks passed. The dedicated worktree /home/openclaw/projects/gisce-ti/worktrees/apply_pr-pr-195 was clean and has been removed; the canonical checkout and other worktrees were left untouched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Patch auto version V_._.X

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants