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:
@@ -2076,8 +2076,21 @@ test("compat: _read_os_release parses key=value pairs", _test_r
|
||||
test("compat: _read_os_release returns {} when file missing", _test_read_os_release_handles_missing_file)
|
||||
test("compat: _is_headless returns False when DISPLAY is set", _test_is_headless_with_display)
|
||||
test("compat: _is_headless returns True when no display env vars", _test_is_headless_without_display)
|
||||
def _test_fix_console_encoding_none_stdout():
|
||||
"""fix_console_encoding is a no-op when sys.stdout is None (pythonw.exe)."""
|
||||
original_stdout = sys.stdout
|
||||
try:
|
||||
with _patch("arma_modlist_tools.compat.is_windows", return_value=True):
|
||||
sys.stdout = None
|
||||
_compat_mod.fix_console_encoding() # must not raise
|
||||
assert sys.stdout is None
|
||||
finally:
|
||||
sys.stdout = original_stdout
|
||||
|
||||
|
||||
test("compat: fix_console_encoding is no-op on non-Windows", _test_fix_console_encoding_non_windows_noop)
|
||||
test("compat: fix_console_encoding skips when stdout already UTF-8", _test_fix_console_encoding_already_utf8)
|
||||
test("compat: fix_console_encoding is no-op when stdout is None", _test_fix_console_encoding_none_stdout)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user