fix(cli): add explicit encoding to read_text/write_text calls - #50655
fix(cli): add explicit encoding to read_text/write_text calls#50655AlexFucuson9 wants to merge 1 commit into
Conversation
Path.read_text() and Path.write_text() without explicit encoding default to the system locale encoding. On Windows this is typically cp1252, which causes UnicodeDecodeError for UTF-8 content (JSON configs, user data, service scripts). Add encoding="utf-8" to all read_text() and write_text() calls across 8 CLI files, matching the pattern established in PR NousResearch#50534 (security_audit_startup.py) and ruff rule PLW1514. Fixed files: - main.py: 4 read_text calls - auth.py: 3 read_text calls - banner.py: 1 read_text + 1 write_text - service_manager.py: 1 read_text + 4 write_text - container_boot.py: 1 read_text + 4 write_text - doctor.py: 3 read_text calls - uninstall.py: 2 read_text calls - gateway.py: 1 write_text call
|
Related: part of the systemic |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing the Windows locale issue. The underlying premise still holds on current main, but this commit needs targeted salvage before it can be used.
Problems
gh pr diff 50655changes four already-encoded gateway writes into duplicate keyword arguments. Current main has valid single-keyword calls athermes_cli/gateway.py:2997,:3179,:4003, and:4189; applying the PR versions would be invalid Python.- The current CLI surface has additional bare sibling calls that the commit does not cover:
hermes_cli/container_boot.py:222,441,449,453,460,hermes_cli/service_manager.py:387,990,994,998,1005, andhermes_cli/uninstall.py:90.
Suggested changes
- Preserve only the still-needed bare gateway write at
hermes_cli/gateway.py:4139; drop the four duplicate-keyword gateway hunks. - Re-scan current
hermes_cli/for bareread_text()/write_text()calls and cover the remaining related service and uninstall paths. - Add a narrow non-ASCII persistence regression test for a representative read/write path.
Automated hermes-sweeper review.
| @@ -2708,7 +2708,7 @@ def refresh_systemd_unit_if_needed(system: bool = False) -> bool: | |||
| if _refuse_temp_home_service_write(new_unit, "systemd unit"): | |||
There was a problem hiding this comment.
This call already has encoding="utf-8" on current main (hermes_cli/gateway.py:2997). Adding it a second time produces duplicate keyword arguments and invalid Python; this hunk should be dropped during salvage.
|
Merged via PR #71078 — your commit(s) were cherry-picked onto current main with your authorship preserved in git log (rebase merge). This PR was part of the class-wide close-out of bare |
Summary
Path.read_text()andPath.write_text()without explicit encoding default to the system locale encoding. On Windows this is typicallycp1252, which causesUnicodeDecodeErrorfor UTF-8 content (JSON configs, user data, service scripts).Add
encoding="utf-8"to allread_text()andwrite_text()calls across 8 CLI files, matching the pattern established in PR #50534 and ruff rule PLW1514.Fixed files:
main.py: 4 read_text callsauth.py: 3 read_text callsbanner.py: 1 read_text + 1 write_textservice_manager.py: 1 read_text + 4 write_textcontainer_boot.py: 1 read_text + 4 write_textdoctor.py: 3 read_text callsuninstall.py: 2 read_text callsgateway.py: 1 write_text callWhy this matters
Hermes runs on Windows, macOS, and Linux. On Windows, the default encoding for
Path.read_text()iscp1252, notutf-8. JSON files written with UTF-8 content (emojis, non-ASCII usernames, i18n strings) will fail to read back on Windows without explicit encoding.Test plan
ruff check --select PLW1514 hermes_cli/passes