Skip to content

fix(cli): resolve Windows UnicodeEncodeError in soul status (#267)#268

Open
sshekhar563 wants to merge 5 commits into
qbtrix:devfrom
sshekhar563:fix/windows-unicode-status-267
Open

fix(cli): resolve Windows UnicodeEncodeError in soul status (#267)#268
sshekhar563 wants to merge 5 commits into
qbtrix:devfrom
sshekhar563:fix/windows-unicode-status-267

Conversation

@sshekhar563

Copy link
Copy Markdown
Collaborator

What

Fixes soul status and soul inspect crashing on Windows with UnicodeEncodeError.

Fixes #267

Root Cause

Windows legacy console uses cp1252 encoding. Rich library outputs Unicode characters
(█, ░, emoji) that cp1252 can't encode → crash.

Fix

Reconfigure stdout/stderr to 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
  • 229/231 CLI tests pass (2 pre-existing env failures unchanged)

@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label Jun 25, 2026

@prakashUXtech prakashUXtech 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.

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
@sshekhar563 sshekhar563 force-pushed the fix/windows-unicode-status-267 branch from 4b59cf1 to ebe6cfb Compare July 3, 2026 11:58
- 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
@sshekhar563 sshekhar563 requested a review from prakashUXtech July 3, 2026 15:55
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.

2 participants