fix(cli): resolve Windows UnicodeEncodeError in soul status (#267)#268
fix(cli): resolve Windows UnicodeEncodeError in soul status (#267)#268sshekhar563 wants to merge 5 commits into
Conversation
|
This PR has been automatically marked as stale because it has not had activity in the last 14 days. It will be closed in 7 days if no further activity occurs. If you're still working on this, please push an update or leave a comment. |
prakashUXtech
left a comment
There was a problem hiding this comment.
Thanks for reporting this and turning around a fix. Reconfiguring stdout to UTF-8 before the Rich Console() is the right approach, and it covers every command, not just soul status.
Two changes before it goes in:
1. A regression test. This reproduces off Windows too: running soul status in a subprocess with PYTHONIOENCODING=cp1252 triggers the same crash on Linux and macOS. So a test can live in tests/test_cli/ and actually run in CI.
2. Gate on the encoding, not the platform. The same UnicodeEncodeError fires on Linux under a C or POSIX locale (Docker images, cron jobs, ssh sessions where stdout is ASCII), which the sys.platform == "win32" check leaves broken. Checking sys.stdout.encoding instead covers both cases, and it makes the regression test above runnable on the Linux CI runners (the matrix is ubuntu-only, so a Windows-gated fix can't be exercised there at all).
Something like reconfiguring when (stream.encoding or "").lower().replace("-", "") != "utf8" for each of stdout and stderr.
One heads-up that isn't on you: the reason none of this showed as a failing check is that CI doesn't run tests on PRs targeting dev right now. I'm fixing that in a separate PR.
Reconfigure stdout/stderr to UTF-8 on Windows before Rich Console init. The legacy Windows console uses cp1252 encoding which cannot render Unicode characters (progress bars, emoji) that Rich outputs, causing soul status and soul inspect to crash. Fixes qbtrix#267
Address review feedback: - Check sys.stdout.encoding instead of sys.platform == win32 - Covers Windows cp1252, Linux C/POSIX, Docker, cron, SSH - Add regression test running soul status with PYTHONIOENCODING=cp1252 - Add unit tests for _ensure_utf8 helper
4b59cf1 to
ebe6cfb
Compare
- Use codecs.lookup() to recognize cp65001 and other UTF-8 aliases - Add ValueError to except clause for unusual reconfigure() impls - Fix subprocess test: use encoding='utf-8', errors='replace' instead of text=True - Use json.dumps for safe path quoting in test setup script
What
Fixes
soul statusandsoul inspectcrashing on Windows withUnicodeEncodeError.Fixes #267
Root Cause
Windows legacy console uses
cp1252encoding. Rich library outputs Unicode characters(█, ░, emoji) that
cp1252can't encode → crash.Fix
Reconfigure
stdout/stderrto UTF-8 on Windows before Rich Console initialization(3 lines, zero risk to Linux/Mac).
Testing
soul status test.soul→ ✅ Works (was crashing before)soul inspect test.soul→ ✅ Works