fix(cli): enforce utf-8 encoding for screenshot text outputs - #13084
Conversation
In `sdks/python-cli/omi_cli/commands/local.py`, `_write_screenshot_result()` invoked `output.write_text()` using the system default encoding. On Windows locales with legacy non-UTF-8 code pages, saving OCR text or metadata containing multilingual characters raises `UnicodeEncodeError`. Explicitly specify `encoding="utf-8"` on all `write_text()` calls in `_write_screenshot_result()`. Fixes BasedHardware#13072
|
Thanks @Aj2280 — clean, well-scoped fix for #13072, and the tests are the right shape for it. What I verified:
One non-blocking note: on interpreters running with UTF-8 mode enabled ( Good first contribution. This feedback is AI-generated on behalf of the Omi maintainers; leaving the merge decision to a human maintainer. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
fix(cli): enforce utf-8 encoding for screenshot text outputs. Confidence 5/5 (root cause stated, fixes #13072, tiny scoped diff, regression tests added). Confirmed bug still present on main (write_text calls in local.py lack encoding param).
Summary
In
sdks/python-cli/omi_cli/commands/local.py,_write_screenshot_result()invokedPath.write_text()without specifyingencoding="utf-8". On Windows locales using legacy non-UTF-8 default encodings (e.g.cp1252), saving plain-text OCR or metadata containing multilingual characters (e.g.Screenshot OCR: café 東京) fails withUnicodeEncodeError.This PR explicitly sets
encoding="utf-8"on alloutput.write_text()calls in_write_screenshot_result(), ensuring reliable UTF-8 screenshot text exports across all platforms and locale settings.Fixes #13072
Changes
sdks/python-cli/omi_cli/commands/local.py:encoding="utf-8"for string outputs, dictionary content outputs, and JSON fallback outputs in_write_screenshot_result().sdks/python-cli/tests/test_local_screenshot_encoding.py:cp1252) are simulated.Verification
sdks/python-cli/venv/bin/pytest sdks/python-cli/tests/test_local_screenshot_encoding.py -v: 4/4 passed.sdks/python-cli/venv/bin/pytest sdks/python-cli/tests/: 132 passed, 1 skipped.scripts/pr-preflight.Failure-Class: none