make_game: a folder whose name the locale cannot decode no longer stops --pick on Linux (MAKE-GAME-PICK-FSDECODE) #1347

Open
github-bot wants to merge 1 commit from github-bot/gh-1347 into main AGit
Owner

@⁠PierreEbele on GitHub · 2026-11-24 22:07 UTC · original
PierreEbele:make-game-pick-fsdecode → main · +103 −4 · 2 files · 1 commits · open

On Linux and the BSDs, --pick opens the desktop's folder dialog through kdialog or zenity (native_ask, make_game.py). Its answer was read with subprocess.run(..., text=True), so choosing a folder whose name is not valid in the locale's encoding (e.g. bytes b"/tmp/caf\xe9" under a UTF-8 locale) raised UnicodeDecodeError, which pick_game does not catch (it only expects OSError from the tool), and the build stopped with a traceback.

What changes:

  • native_ask reads the answer as bytes and decodes it with os.fsdecode, so the path round-trips (os.fsencode gives back the bytes the dialog printed). Return codes keep their meaning (1 = cancelled, other non-zero = OSError).
  • print()ing such a str on a UTF-8 terminal raises UnicodeEncodeError, so the two chose ... in <folder> log lines go through a new show_path() that shows the undecodable bytes escaped (/tmp/caf\xe9). Display only: the path handed to the build is unchanged.
  • New tests/test_make_game_pick_fsdecode.py (CPU only, no display, no game files): a stand-in kdialog printing raw bytes, show_path against a strict UTF-8 stream, and pick_game end to end with a mocked dialog. Windows is skipped (the native dialogs never run there); the stand-in test skips itself when the temp folder is mounted noexec.

Tested on Linux arm64, no network, Python 3.12, python3 -I:

  • New test on main 4a50cafc: FAILED (errors=5), including UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in native_ask.
  • On this branch: Ran 5 tests ... OK (with an executable TMPDIR); tests/test_make_game_pick.py OK; make_game.py --help OK; scripts/check_no_game_data.py clean on both files.

Takes the finding posted by Snooozs in #14 (read in the code there, reproduced here).

AI-assisted (Claude Code and Mistral Vibe).

Claimed in the coordination issue as: MAKE-GAME-PICK-FSDECODE

🤖 Generated with Claude Code

**@⁠PierreEbele** on GitHub · 2026-11-24 22:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1347) `PierreEbele:make-game-pick-fsdecode` → `main` · +103 −4 · 2 files · 1 commits · open On Linux and the BSDs, `--pick` opens the desktop's folder dialog through kdialog or zenity (`native_ask`, `make_game.py`). Its answer was read with `subprocess.run(..., text=True)`, so choosing a folder whose name is not valid in the locale's encoding (e.g. bytes `b"/tmp/caf\xe9"` under a UTF-8 locale) raised `UnicodeDecodeError`, which `pick_game` does not catch (it only expects `OSError` from the tool), and the build stopped with a traceback. What changes: - `native_ask` reads the answer as bytes and decodes it with `os.fsdecode`, so the path round-trips (`os.fsencode` gives back the bytes the dialog printed). Return codes keep their meaning (1 = cancelled, other non-zero = `OSError`). - `print()`ing such a str on a UTF-8 terminal raises `UnicodeEncodeError`, so the two `chose ... in <folder>` log lines go through a new `show_path()` that shows the undecodable bytes escaped (`/tmp/caf\xe9`). Display only: the path handed to the build is unchanged. - New `tests/test_make_game_pick_fsdecode.py` (CPU only, no display, no game files): a stand-in kdialog printing raw bytes, `show_path` against a strict UTF-8 stream, and `pick_game` end to end with a mocked dialog. Windows is skipped (the native dialogs never run there); the stand-in test skips itself when the temp folder is mounted `noexec`. Tested on Linux arm64, no network, Python 3.12, `python3 -I`: - New test on `main` 4a50cafc: `FAILED (errors=5)`, including `UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9` in `native_ask`. - On this branch: `Ran 5 tests ... OK` (with an executable `TMPDIR`); `tests/test_make_game_pick.py` OK; `make_game.py --help` OK; `scripts/check_no_game_data.py` clean on both files. Takes the finding posted by Snooozs in #14 (read in the code there, reproduced here). AI-assisted (Claude Code and Mistral Vibe). Claimed in the coordination issue as: MAKE-GAME-PICK-FSDECODE 🤖 Generated with [Claude Code](https://claude.com/claude-code)
native_ask ran kdialog/zenity with subprocess.run(text=True), so a
folder whose name the locale encoding cannot decode made the call raise
UnicodeDecodeError, which pick_game does not catch (it only catches
OSError). The dialog's answer is now read as bytes and decoded with
os.fsdecode, whose surrogateescape str round-trips through os.fsencode
to the same bytes the tool printed; the return codes keep their meaning.

print()ing that str on a UTF-8 terminal raises UnicodeEncodeError, so the
log lines about the chosen folder go through the new show_path(), which
shows the undecodable bytes escaped; the path handed to the build is
untouched. tests/test_make_game_pick_fsdecode.py covers both with a
stand-in dialog printing raw bytes (python -I, standard library only).

AI-assisted.

Co-Authored-By: Mistral Vibe <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:48:15 +00:00
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-24 23:40 UTC · original

Verified on Windows host (AI-assisted review).

  • python -I tests/test_make_game_pick_fsdecode.py: 5 tests, 3 skipped (they target kdialog/zenity, which never run on Windows), 2 pass — the non-dialog show_path() unit tests.
  • python -I -m compileall make_game.py clean; python -I make_game.py --help prints usage; tests/test_text_write_line_endings.py still passes.
  • The change is confined to the non-Windows dialog path (native_ask bytes + os.fsdecode, show_path used only in the log line), so Windows-native behaviour is unchanged by inspection: subprocess.run without text=True returns bytes and os.fsdecode is a no-op round-trip for valid encodings. Cannot exercise the surrogateescape path on Windows; the skipped tests cover it on Linux.

Verdict: looks correct, no Windows regressions found. The real verification needs a Linux CI run for the 3 skipped tests.

**@⁠whoalin1** on GitHub · 2026-11-24 23:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1347#issuecomment-7147662197) Verified on Windows host (AI-assisted review). - `python -I tests/test_make_game_pick_fsdecode.py`: 5 tests, 3 skipped (they target kdialog/zenity, which never run on Windows), 2 pass — the non-dialog show_path() unit tests. - `python -I -m compileall make_game.py` clean; `python -I make_game.py --help` prints usage; `tests/test_text_write_line_endings.py` still passes. - The change is confined to the non-Windows dialog path (native_ask bytes + os.fsdecode, show_path used only in the log line), so Windows-native behaviour is unchanged by inspection: subprocess.run without text=True returns bytes and os.fsdecode is a no-op round-trip for valid encodings. Cannot exercise the surrogateescape path on Windows; the skipped tests cover it on Linux. Verdict: looks correct, no Windows regressions found. The real verification needs a Linux CI run for the 3 skipped tests.
github-bot force-pushed github-bot/gh-1347 from 19a407d2dd to 82d0dfcc40 2026-11-26 16:01:30 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1347/head:github-bot/gh-1347'
git switch 'github-bot/gh-1347'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1347'
git switch 'github-bot/gh-1347'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1347'
git switch 'github-bot/gh-1347'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1347'
git switch 'main'
git merge --squash 'github-bot/gh-1347'
git switch 'main'
git merge --ff-only 'github-bot/gh-1347'
git switch 'main'
git merge 'github-bot/gh-1347'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.