fix(generator): fall back to the login link on cp1252 consoles - #195
Open
MohammedAlkindi wants to merge 1 commit into
Open
fix(generator): fall back to the login link on cp1252 consoles#195MohammedAlkindi wants to merge 1 commit into
MohammedAlkindi wants to merge 1 commit into
Conversation
Redirected stdout on Windows uses the ANSI code page, which cannot encode the half-block characters print_ascii emits, so the generator crashed with UnicodeEncodeError before showing any login path (chigwell#150). Render the QR art only when stdout can encode it, otherwise print the tg:// login link, and reconfigure stdio with errors=replace so no other print site (account labels, error text) can abort a login mid-flight.
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.
Fixes #150.
On Windows, redirected stdout falls back to the ANSI code page (cp1252). The half-block characters from
print_asciicannot be encoded, so_render_qrdies withUnicodeEncodeErrorbefore any login path is shown. Reproduced on Windows 11, Python 3.13, piped stdout.Two changes in
session_string_generator.py:_render_qrnow checks whether stdout can encode the rendered art and prints the tg:// login link instead when it cannot. Same fallback idea qsardor proposed in the issue body; I test encodability up front instead of catching, because with hardened stdio (below) the print no longer raises, it would just draw an unscannable grid of?.main()reconfigures stdout/stderr witherrors="replace". As tonydzi noted, the QR art is only the first member of this failure class: the account label and error text also reach stdout and can carry non-latin characters. This stops any of them from aborting a login, and it helps users who cannot setPYTHONUTF8=1in their launcher.Three regression tests added. The fallback test fails on main with the exact error from the issue. black, flake8 and the whitespace hooks pass on the changed files; the docker compose hook needs a local
.envand passes once one exists.Verification on Windows 11, Python 3.13
Before, piped stdout under cp1252:
After, same environment:
pytest tests/test_session_string_generator.py: 15 passed.
Full suite: 276 passed, 8 failed identically on main and on this branch
(POSIX permission and pool-lock tests that do not hold on Windows).