Skip to content

fix(cli): don't crash on redirected output with a legacy code page - #645

Open
Siddhanthguptaa wants to merge 1 commit into
ControlCore-Project:devfrom
Siddhanthguptaa:fix/cli-redirected-output-encoding
Open

Siddhanthguptaa wants to merge 1 commit into
ControlCore-Project:devfrom
Siddhanthguptaa:fix/cli-redirected-output-encoding

Conversation

@Siddhanthguptaa

Copy link
Copy Markdown

Fixes #644

When output is redirected on Windows, stdout uses cp1252 and the CLI died on the first "✓" with UnicodeEncodeError. The cli() group callback now sets errors="replace" on stdout, so characters the code page can't encode print as ? instead of crashing. Output in UTF-8 terminals is unchanged, and importing concore_cli doesn't touch the streams.

Testing

  • New test test_cli_redirected_output_with_legacy_encoding runs init in a subprocess with PYTHONIOENCODING=cp1252 and captured output; it fails on current dev with the UnicodeEncodeError and passes with this change (works on any OS).
  • pytest on Windows 11 / Python 3.11: 239 passed, 12 skipped. ruff check . and ruff format --check . pass.
  • Manual on Windows: concore init demo > out.txt now exits 0 (was 1); the file shows ? Project created successfully!.

With output redirected on Windows, stdout uses cp1252 and printing the
check mark raised UnicodeEncodeError, so even `concore init demo > f`
exited 1. Set errors="replace" on stdout when the CLI is invoked so
unencodable characters are replaced instead.
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.

1 participant