Private
Public Access
0
0

TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L1647 render_main_interface focus_response to Result[T] (Phase 10 site 8)

Extracted _focus_response_window_result() -> Result[None] helper above
the call site in render_main_interface.
ANTI-SLIMING: full Result[T] propagation (NO bare-except+pass). 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 render_main_interface code preserves its behavior, calls
the helper, drains errors to app._last_request_errors.

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

Audit: L1647 reclassified from INTERNAL_SILENT_SWALLOW (6 sites remaining,
was 7). New helper L1647 is INTERNAL_COMPLIANT.
This commit is contained in:
2026-06-20 00:53:35 -04:00
parent 24191c827d
commit 9188e548ff
2 changed files with 62 additions and 4 deletions
+26 -4
View File
@@ -1644,10 +1644,32 @@ def render_main_interface(app: App) -> None:
if app.controller._process_pending_tool_calls(): app._tool_log_dirty = True
if app._pending_focus_response:
app._pending_focus_response = False
try:
imgui.set_window_focus("Response") # type: ignore[call-arg]
except:
pass
focus_result = _focus_response_window_result()
if not focus_result.ok:
if not hasattr(app, '_last_request_errors'): app._last_request_errors = []
app._last_request_errors.append(("render_main_interface.focus_response", focus_result.errors[0]))
def _focus_response_window_result() -> Result[None]:
"""Drain-aware variant of render_main_interface imgui.set_window_focus try block (L1647 INTERNAL_SILENT_SWALLOW).
Extracts the thirdparty imgui.set_window_focus("Response") try/except from
render_main_interface into a Result-returning helper. On exception (native
bundle error, IM_ASSERT), converts to ErrorInfo (logging NOT a drain per
the user's principle 2026-06-17). The caller drains to
app._last_request_errors.
[C: src/gui_2.py:render_main_interface (L1647 legacy wrapper)]
"""
try:
imgui.set_window_focus("Response") # type: ignore[call-arg]
return Result(data=None)
except Exception as e:
return Result(data=None, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message=f"imgui.set_window_focus('Response') failed: {e}",
source="gui_2._focus_response_window_result",
original=e,
)])
#endregion: Process GUI task queue
render_track_proposal_modal(app)
+36
View File
@@ -2032,4 +2032,40 @@ def test_phase_10_l1466_close_vscode_diff_terminate_result_failure():
assert "process already exited" in err.message
def test_phase_10_l1647_focus_response_window_result_success():
"""
L1647 _focus_response_window_result returns Result(data=None) on success.
The helper extracts the imgui.set_window_focus("Response") try/except from
render_main_interface into a Result-returning helper. On success, returns
Result(data=None).
"""
from unittest.mock import MagicMock, patch
import src.gui_2 as gui2_mod
with patch("src.gui_2.imgui.set_window_focus", return_value=None):
result = gui2_mod._focus_response_window_result()
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
assert result.data is None
def test_phase_10_l1647_focus_response_window_result_failure():
"""
L1647 _focus_response_window_result returns Result(data=None, errors=[ErrorInfo]) on failure.
When imgui.set_window_focus("Response") raises (e.g., native bundle
error, IM_ASSERT), the helper converts to ErrorInfo. The caller
(render_main_interface) drains to self._last_request_errors.
"""
from unittest.mock import patch
import src.gui_2 as gui2_mod
with patch("src.gui_2.imgui.set_window_focus", side_effect=RuntimeError("IM_ASSERT: window scope")):
result = gui2_mod._focus_response_window_result()
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._focus_response_window_result"
assert "IM_ASSERT" in err.message