Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L1152 _gui_func entry log to Result[T] (Phase 10 site 6)
Extracted _gui_func_entry_log_result(app) -> Result[None] helper above the App._gui_func method. ANTI-SLIMING: full Result[T] propagation (NO except+pass-after-log). The helper returns Result(data=None) on success or Result(data=None, errors=[ErrorInfo]) on exception (logging NOT a drain per the user's principle 2026-06-17). The legacy _gui_func method preserves its signature, calls the helper, drains errors to self._last_request_errors, and proceeds with the rest of the render loop. Tests: 2 new tests verify both paths (success and OSError). Audit: L1152 reclassified from INTERNAL_SILENT_SWALLOW (8 sites remaining, was 9). New helper L1152 is INTERNAL_COMPLIANT.
This commit is contained in:
@@ -1947,4 +1947,47 @@ def test_phase_10_l1052_shutdown_save_ini_result_failure():
|
||||
assert "disk full" in err.message
|
||||
|
||||
|
||||
def test_phase_10_l1152_gui_func_entry_log_result_success():
|
||||
"""
|
||||
L1152 _gui_func_entry_log_result returns Result(data=None) on success.
|
||||
|
||||
The helper extracts the startup-timing sys.stderr.write from
|
||||
App._gui_func into a Result-returning helper. On success, returns
|
||||
Result(data=None). The legacy _gui_func method proceeds to the rest
|
||||
of the render loop.
|
||||
"""
|
||||
from unittest.mock import MagicMock
|
||||
import src.gui_2 as gui2_mod
|
||||
app = MagicMock()
|
||||
app.controller = MagicMock()
|
||||
app.controller._init_start_ts = 1000.0
|
||||
result = gui2_mod._gui_func_entry_log_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is None
|
||||
|
||||
|
||||
def test_phase_10_l1152_gui_func_entry_log_result_failure():
|
||||
"""
|
||||
L1152 _gui_func_entry_log_result returns Result(data=None, errors=[ErrorInfo]) on failure.
|
||||
|
||||
When the sys.stderr.write or sys.stderr.flush raises (e.g., broken pipe),
|
||||
the helper converts to ErrorInfo. The legacy _gui_func method drains to
|
||||
self._last_request_errors and proceeds with the rest of the render loop
|
||||
(preserving the original behavior of continuing past the failure).
|
||||
"""
|
||||
from unittest.mock import MagicMock, patch
|
||||
import src.gui_2 as gui2_mod
|
||||
app = MagicMock()
|
||||
app.controller = MagicMock()
|
||||
app.controller._init_start_ts = 1000.0
|
||||
with patch("src.gui_2.sys.stderr.write", side_effect=OSError("broken pipe")):
|
||||
result = gui2_mod._gui_func_entry_log_result(app)
|
||||
assert not result.ok, f"Expected ok=False on failure, got data: {result.data}"
|
||||
assert result.data is None
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._gui_func_entry_log_result"
|
||||
assert "broken pipe" in err.message
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user