Repository navigation
Don't crash on characters the output can't encode (Windows pipes and files) - #140
Merged
Merged
Conversation
On Windows, output sent to a pipe or a file uses the ANSI code page, so an emoji or an arrow quoted from a document raised UnicodeEncodeError partway through `py-doc lint` (and any other command) when its output was redirected. Every console command now sets errors="replace" on stdout and stderr when they are not UTF-8, so such a character prints as "?". UTF-8 output and console windows are left as they are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows, a pipe or a file gets the ANSI code page (cp1252 and the like), not UTF-8. When a lint finding quoted an emoji or an arrow from a document,
py-doc lint ... > report.txtstopped partway withUnicodeEncodeErrorand exit status 1. This happened on markbac.github.io's glossary and blog.Every console command (
py-docand the oldpy-doc2docx,py-doc2slides,py-doclintandpy-c4-exporter) now callssafe_console()first. It setserrors="replace"on stdout and stderr when they aren't UTF-8, so such a character prints as?. UTF-8 output (Linux, macOS, CI) and Windows console windows are unchanged.Testing
tests/test_console.py: a cp1252 stream gets?instead of an exception, and a UTF-8 stream is left strict.py-doc lint content/glossary > fileon Windows crashed before and now exits 0.ruff check: clean.🤖 Generated with Claude Code