fix: guard against None stdout in fix_console_encoding for pythonw.exe
When launched via pythonw.exe (no console), sys.stdout/stderr are None. Accessing .encoding on None raised AttributeError, caught by the GUI's pipeline import guard and shown as 'Failed to load pipeline'. Added None check before the encoding check in fix_console_encoding(), added a test, and documented the pitfall in CLAUDE.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -147,6 +147,10 @@ get_language() # → "vi"
|
||||
|
||||
Minimum is Python **3.9**. All files that use `X | Y` union type annotations **must** have `from __future__ import annotations` as the first import. Without it, the `|` syntax raises `TypeError` at runtime on Python < 3.10. Every module in `arma_modlist_tools/` already has it; any new CLI script you add must include it too.
|
||||
|
||||
### `fix_console_encoding` — `None` stdout guard
|
||||
|
||||
When the GUI is launched via `pythonw.exe` (no console window), Python sets `sys.stdout` and `sys.stderr` to `None`. `fix_console_encoding()` must check `if sys.stdout is None or sys.stderr is None: return` **before** accessing `.encoding`, otherwise it raises `AttributeError: 'NoneType' object has no attribute 'encoding'`. This error surfaces in the GUI as *"Failed to load pipeline"* because `run.py` calls `fix_console_encoding()` at module level and the exception is caught by the pipeline import guard.
|
||||
|
||||
## Test Suite
|
||||
|
||||
`test_suite.py` uses a custom harness (no pytest/unittest dependency). Structure:
|
||||
|
||||
Reference in New Issue
Block a user