Skip to content

fix(console): centralize UTF-8 stdio so emoji logs never fail translations - #186

Merged
hydropix merged 2 commits into
mainfrom
fix/utf8-stdio-184
Jun 2, 2026
Merged

hydropix merged 2 commits into
mainfrom
fix/utf8-stdio-184

Conversation

@hydropix

@hydropix hydropix commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #184: emoji status lines printed by providers (💬, ✅, ❌, ⚠️) crash on
Windows cp1252 consoles with UnicodeEncodeError. Worse, when the failing
print() sits inside a provider's broad except, it is mistaken for a request
failure and the unit's translation fails despite a valid model response.

Every entrypoint already worked around this except the main CLI
(translate.py), and with two divergent implementations.

Changes

  • src/utils/console.py — new ensure_utf8_stdio() helper: idempotent, prefers
    TextIOWrapper.reconfigure(), falls back to wrapping the raw buffer, never
    raises.
  • translate.py — wire in the helper (the entrypoint that was missing it).
  • translation_api.py, benchmark/cli.py — replace the two prior divergent
    copies with the shared helper.
  • src/__version__.py — bump to 1.4.5 (patch) to cut a release.

Tests

  • tests/unit/test_console_utf8.py — 5 unit tests: reconfigure path,
    idempotency on already-UTF-8 streams, buffer-wrapping fallback,
    reconfigure-raises fallback, and missing streams.
  • Full suite green: 1129 passed, 1 skipped.
  • Verified end-to-end on a real cp1252 console: a Poe CLI translation now prints
    its 💬 token line and completes, where it previously crashed.

Release / builds

Builds (Windows, macOS, Docker) trigger on a v* tag. After merge, tagging
v1.4.5 on main will kick off the executable + Docker release.

Fixes #184

hydropix and others added 2 commits June 2, 2026 23:24
…tions

Providers print status lines with emoji (💬, ✅, ❌, ⚠️). On Windows cp1252
consoles those raise UnicodeEncodeError, and inside a provider's broad
`except` the failing print() was mistaken for a request failure, so the
unit's translation failed despite a valid model response.

Every entrypoint already worked around this, except the main CLI
(translate.py), and with two divergent implementations. Replace them with
a single ensure_utf8_stdio() helper (src/utils/console.py): idempotent,
prefers TextIOWrapper.reconfigure(), falls back to wrapping the raw
buffer, and never raises.

Wired into translate.py (the missing one), translation_api.py and
benchmark/cli.py (deduplicating the two prior copies).

Verified end-to-end on a real cp1252 console: a Poe CLI translation now
prints its 💬 token line and completes, where it previously crashed.

Tests: 5 unit tests for the helper (reconfigure, idempotency, buffer
fallback, reconfigure-raises fallback, missing streams). Full suite green
(1129 passed, 1 skipped).

Fixes #184

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hydropix
hydropix merged commit 16907ea into main Jun 2, 2026
1 check passed
@hydropix
hydropix deleted the fix/utf8-stdio-184 branch June 2, 2026 21:28
losskot pushed a commit to losskot/TranslateBooksWithLLMs that referenced this pull request Jul 10, 2026
…tions (hydropix#186)

* fix(console): centralize UTF-8 stdio so emoji logs never fail translations

Providers print status lines with emoji (💬, ✅, ❌, ⚠️). On Windows cp1252
consoles those raise UnicodeEncodeError, and inside a provider's broad
`except` the failing print() was mistaken for a request failure, so the
unit's translation failed despite a valid model response.

Every entrypoint already worked around this, except the main CLI
(translate.py), and with two divergent implementations. Replace them with
a single ensure_utf8_stdio() helper (src/utils/console.py): idempotent,
prefers TextIOWrapper.reconfigure(), falls back to wrapping the raw
buffer, and never raises.

Wired into translate.py (the missing one), translation_api.py and
benchmark/cli.py (deduplicating the two prior copies).

Verified end-to-end on a real cp1252 console: a Poe CLI translation now
prints its 💬 token line and completes, where it previously crashed.

Tests: 5 unit tests for the helper (reconfigure, idempotency, buffer
fallback, reconfigure-raises fallback, missing streams). Full suite green
(1129 passed, 1 skipped).

Fixes hydropix#184

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(release): bump version to 1.4.5

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: hydropix <5154373+hydropix@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emoji print() crashes on Windows cp1252 consoles and can fail translations

1 participant