TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L612 _post_init callback to Result[T] (Phase 10 site 3)

Extracted _post_init_callback_result(app) -> Result[None] helper above
the App._post_init method.
ANTI-SLIMING: full Result[T] propagation (NO pass-after-logging). 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 _post_init method preserves its signature and calls the helper,
draining errors to self._startup_timeline_errors.

Tests: 2 new tests verify both paths (success and RuntimeError).

Audit: L612 reclassified from INTERNAL_SILENT_SWALLOW (10 sites remaining,
was 11). New helper L612 is INTERNAL_COMPLIANT.
This commit is contained in:
ed
2026-06-20 00:44:30 -04:00
parent 6585cdc5e7
commit e761244c4a
2 changed files with 78 additions and 13 deletions
+28 -5
View File
@@ -598,7 +598,30 @@ class App:
def _handle_save_anyway_click(self) -> None: def _handle_save_anyway_click(self) -> None:
self._pending_save_anyway_click = True self._pending_save_anyway_click = True
def _post_init(self) -> None: def _post_init_callback_result(app: "App") -> Result[None]:
"""Drain-aware variant of App._post_init (L612 INTERNAL_SILENT_SWALLOW).
Extracts the controller.on_warmup_complete callback registration from
App._post_init into a Result-returning helper. On exception, returns
Result(data=None, errors=[ErrorInfo]) so the legacy wrapper can drain
the error to self._startup_timeline_errors. On success, the lambda
callback is registered and Result(data=None) is returned.
[C: src/gui_2.py:App._post_init (L612 legacy wrapper)]
"""
#Note(Ed): Exception(Thirdparty)
try:
app.controller.on_warmup_complete(lambda status: _on_warmup_complete_callback(app, status))
return Result(data=None)
except Exception as e:
return Result(data=None, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message=f"on_warmup_complete callback registration failed: {e}",
source="gui_2._post_init_callback_result",
original=e,
)])
def _post_init(self) -> None:
theme.apply_current() theme.apply_current()
# Register warmup completion callback (sub-track 4 of # Register warmup completion callback (sub-track 4 of
# startup_speedup_20260606). The callback runs on a background # startup_speedup_20260606). The callback runs on a background
@@ -606,10 +629,10 @@ class App:
# is safe. The render_warmup_status_indicator() function reads # is safe. The render_warmup_status_indicator() function reads
# the timestamp to show a brief "ready" tag for 3 seconds. # the timestamp to show a brief "ready" tag for 3 seconds.
if hasattr(self.controller, "on_warmup_complete"): if hasattr(self.controller, "on_warmup_complete"):
#Note(Ed): Exception(Thirdparty) cb_result = _post_init_callback_result(self)
try: if not cb_result.ok:
self.controller.on_warmup_complete(lambda status: _on_warmup_complete_callback(self, status)) if not hasattr(self, '_startup_timeline_errors'): self._startup_timeline_errors = []
except Exception: pass self._startup_timeline_errors.append(("_post_init.callback", cb_result.errors[0]))
self._diag_layout_state() self._diag_layout_state()
def _diag_layout_state(self) -> None: def _diag_layout_state(self) -> None:
+42
View File
@@ -1815,4 +1815,46 @@ def test_phase_10_l264_resolve_font_path_result_is_relative_to_raises():
assert err.source == "gui_2._resolve_font_path_result" assert err.source == "gui_2._resolve_font_path_result"
def test_phase_10_l612_post_init_callback_result_success():
"""
L612 _post_init_callback_result returns Result(data=None) on success.
The helper extracts the warmup-complete callback registration from
App._post_init into a Result-returning helper. On success, it registers
the lambda callback via self.controller.on_warmup_complete() and returns
Result(data=None).
"""
from unittest.mock import MagicMock
import src.gui_2 as gui2_mod
app = MagicMock()
app.controller = MagicMock()
result = gui2_mod._post_init_callback_result(app)
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
assert result.data is None
app.controller.on_warmup_complete.assert_called_once()
def test_phase_10_l612_post_init_callback_result_failure():
"""
L612 _post_init_callback_result returns Result(data=None, errors=[ErrorInfo]) on failure.
When self.controller.on_warmup_complete() raises (e.g., controller not
ready or invalid callback), the helper converts to ErrorInfo and returns
Result(data=None, errors=[ErrorInfo]). The legacy _post_init wrapper
drains to self._startup_timeline_errors.
"""
from unittest.mock import MagicMock
import src.gui_2 as gui2_mod
app = MagicMock()
app.controller = MagicMock()
app.controller.on_warmup_complete.side_effect = RuntimeError("controller not ready")
result = gui2_mod._post_init_callback_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._post_init_callback_result"
assert "controller not ready" in err.message