TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L728 run() immapp call to Result[T] (Phase 10 site 4)

Extracted _run_immapp_result(app) -> Result[None] helper above the
App.run method.
ANTI-SLIMING: full Result[T] propagation (NO pass-after-print). 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 run() wrapper sets
controller._gui_degraded_reason and _last_imgui_assert (the canonical
degradation drain), appends to _startup_timeline_errors, and returns
WITHOUT the original stderr.print logging.

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

Audit: L728 reclassified from INTERNAL_SILENT_SWALLOW (10 sites remaining,
was 11). New helper L728 is INTERNAL_COMPLIANT.
This commit is contained in:
ed
2026-06-20 00:46:43 -04:00
parent e761244c4a
commit ad702f7e88
2 changed files with 83 additions and 27 deletions
+37 -27
View File
@@ -745,33 +745,43 @@ def _post_init(self) -> None:
self.runner_params.callbacks.post_init = _profiled_post_init
self._fetch_models(self.current_provider)
md_options = markdown_helper.get_renderer().options
#Note(Ed): Exception(Thirdparty)
try:
immapp.run(self.runner_params, add_ons_params=immapp.AddOnsParams(with_markdown_options=md_options))
except RuntimeError as _immapp_exc:
# ImGui scope errors (IM_ASSERT) and other native-bundle exceptions
# surface as RuntimeError. Per user feedback 2026-06-08, do not
# silently swallow — record the failure on the controller so the
# /api/gui_health endpoint and the GUI logs can surface it. Keep the
# process alive so the hook server (separate thread) can continue
# serving tests; the next test can detect the degraded state and
# fail fast with a clear message.
if hasattr(self, "controller") and self.controller is not None:
self.controller._gui_degraded_reason = (
f"immapp.run raised {type(_immapp_exc).__name__}: {_immapp_exc}"
)
self.controller._last_imgui_assert = traceback.format_exc()
print(
f"[GUI-DEGRADED] immapp.run raised: {_immapp_exc}",
file = sys.stderr,
flush = True,
)
print(self.controller._last_imgui_assert if hasattr(self, "controller") and self.controller else "",
file=sys.stderr, flush=True)
return
# On exit (only reached on clean shutdown)
self.shutdown()
session_logger.close_session()
def _run_immapp_result(app: "App") -> Result[None]:
"""Drain-aware variant of App.run immapp.run() call (L728 INTERNAL_SILENT_SWALLOW).
Extracts the thirdparty immapp.run() invocation from App.run into a
Result-returning helper. On exception (RuntimeError from IM_ASSERT or
other native-bundle errors), converts to ErrorInfo. The legacy run
method sets controller._gui_degraded_reason and _last_imgui_assert
(the canonical degradation drain), appends to _startup_timeline_errors,
and returns. NO logging: logging is NOT a drain per the user's
principle 2026-06-17.
[C: src/gui_2.py:App.run (L728 legacy wrapper)]
"""
#Note(Ed): Exception(Thirdparty)
try:
immapp.run(app.runner_params, add_ons_params=immapp.AddOnsParams(with_markdown_options=markdown_helper.get_renderer().options))
return Result(data=None)
except Exception as e:
return Result(data=None, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message=f"immapp.run raised {type(e).__name__}: {e}",
source="gui_2._run_immapp_result",
original=e,
)])
run_result = _run_immapp_result(self)
if not run_result.ok:
err = run_result.errors[0]
if hasattr(self, "controller") and self.controller is not None:
self.controller._gui_degraded_reason = err.message
self.controller._last_imgui_assert = traceback.format_exception(type(err.original), err.original, err.original.__traceback__) if err.original else ""
if not hasattr(self, '_startup_timeline_errors'): self._startup_timeline_errors = []
self._startup_timeline_errors.append(("run.immapp", err))
return
# On exit (only reached on clean shutdown)
self.shutdown()
session_logger.close_session()
def _load_fonts(self) -> None:
from src.startup_profiler import startup_profiler