fix: handle UnicodeEncodeError on Windows terminals (closes #1802)#1856
Open
unn-Known1 wants to merge 1 commit into
Open
fix: handle UnicodeEncodeError on Windows terminals (closes #1802)#1856unn-Known1 wants to merge 1 commit into
unn-Known1 wants to merge 1 commit into
Conversation
Resolves: microsoft#1802 Modified __main__.py to handle UnicodeEncodeError that occurs on Windows when the terminal's charmap codec (cp1252) cannot encode certain Unicode characters. The fix wraps print() calls in try/except blocks to provide a graceful fallback using errors='replace' when the default encoding fails. Changes: - _handle_output(): Added UnicodeEncodeError handling for stdout output - _exit_with_error(): Added UnicodeEncodeError handling for error messages Added test_unicode_encoding_in_cli test to verify the fix works with various Unicode characters including Chinese, Japanese, emojis, and Greek letters.
Author
|
@microsoft-github-policy-service agree |
|
Hey there! I'm still quite new to Python's cross-platform terminal handling. I noticed you chose to fix the UnicodeEncodeError by modifying the stdout stream directly. Could you clarify why that method is preferred? Keep up the good work! |
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
Resolves issue #1802 by handling UnicodeEncodeError that occurs on Windows when the terminal's charmap codec (cp1252) cannot encode certain Unicode characters.
Changes
Modified
__main__.pyto wrap print() calls in try/except blocks to provide a graceful fallback usingerrors='replace'when the default encoding fails.Files Changed
packages/markitdown/src/markitdown/__main__.py_handle_output(): Added UnicodeEncodeError handling for stdout output_exit_with_error(): Added UnicodeEncodeError handling for error messagespackages/markitdown/tests/test_module_misc.pytest_unicode_encoding_in_clitest to verify the fix works with various Unicode charactersTest Coverage
The new test verifies Unicode handling with:
All existing tests continue to pass.