From cab4548f782f5ad9d3de3fa140d7e4defdc7c8f5 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 20 Jun 2026 00:49:00 -0400 Subject: [PATCH] TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L1052 shutdown save_ini to Result[T] (Phase 10 site 5) Extracted _shutdown_save_ini_result(app) -> Result[None] helper above the App.shutdown method. 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 shutdown method preserves its signature, calls the helper, drains errors to self._startup_timeline_errors, and proceeds to self.controller.shutdown(). Tests: 2 new tests verify both paths (success and OSError). Audit: L1052 reclassified from INTERNAL_SILENT_SWALLOW (9 sites remaining, was 10). New helper L1052 is INTERNAL_COMPLIANT. --- src/gui_2.py | 33 ++++++++++++++++++++++------ tests/test_gui_2_result.py | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/gui_2.py b/src/gui_2.py index 1145af65..be970b6e 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -1045,14 +1045,35 @@ def _run_immapp_result(app: "App") -> Result[None]: forces a save of dirty registries/caches, and terminates the active thread pools. SSDL Shape: `[I:save_ini] -> [I:controller_shutdown]` """ - #Note(Ed): Exception(Thirdparty) - try: - if hasattr(self, 'runner_params') and self.runner_params.ini_filename: - imgui.save_ini_settings_to_disk(self.runner_params.ini_filename) - except: - pass + ini_result = _shutdown_save_ini_result(self) + if not ini_result.ok: + if not hasattr(self, '_startup_timeline_errors'): self._startup_timeline_errors = [] + self._startup_timeline_errors.append(("shutdown.save_ini", ini_result.errors[0])) self.controller.shutdown() +def _shutdown_save_ini_result(app: "App") -> Result[None]: + """Drain-aware variant of App.shutdown save_ini try block (L1052 INTERNAL_SILENT_SWALLOW). + + Extracts the thirdparty imgui.save_ini_settings_to_disk try/except from + App.shutdown into a Result-returning helper. On exception, converts to + ErrorInfo (logging NOT a drain per the user's principle 2026-06-17). The + legacy shutdown method drains to self._startup_timeline_errors. + + [C: src/gui_2.py:App.shutdown (L1052 legacy wrapper)] + """ + #Note(Ed): Exception(Thirdparty) + try: + if hasattr(app, 'runner_params') and app.runner_params.ini_filename: + imgui.save_ini_settings_to_disk(app.runner_params.ini_filename) + return Result(data=None) + except Exception as e: + return Result(data=None, errors=[ErrorInfo( + kind=ErrorKind.INTERNAL, + message=f"imgui.save_ini_settings_to_disk failed: {e}", + source="gui_2._shutdown_save_ini_result", + original=e, + )]) + def load_context_preset(self, name: str) -> None: preset = self.controller.load_context_preset(name) from src import models diff --git a/tests/test_gui_2_result.py b/tests/test_gui_2_result.py index 07691191..7ac173ad 100644 --- a/tests/test_gui_2_result.py +++ b/tests/test_gui_2_result.py @@ -1903,4 +1903,48 @@ def test_phase_10_l728_run_immapp_result_failure(): assert "IM_ASSERT" in err.message +def test_phase_10_l1052_shutdown_save_ini_result_success(): + """ + L1052 _shutdown_save_ini_result returns Result(data=None) on success. + + The helper extracts the imgui.save_ini_settings_to_disk() try/except from + App.shutdown into a Result-returning helper. On success, returns + Result(data=None). The legacy shutdown method proceeds to + self.controller.shutdown(). + """ + from unittest.mock import MagicMock, patch + import src.gui_2 as gui2_mod + app = MagicMock() + app.runner_params = MagicMock() + app.runner_params.ini_filename = "manualslop_layout.ini" + with patch("src.gui_2.imgui.save_ini_settings_to_disk", return_value=None): + result = gui2_mod._shutdown_save_ini_result(app) + assert result.ok, f"Expected ok=True on success, got errors: {result.errors}" + assert result.data is None + + +def test_phase_10_l1052_shutdown_save_ini_result_failure(): + """ + L1052 _shutdown_save_ini_result returns Result(data=None, errors=[ErrorInfo]) on failure. + + When imgui.save_ini_settings_to_disk() raises (e.g., disk full, path + not writable), the helper converts to ErrorInfo. The legacy shutdown + method drains to self._startup_timeline_errors and proceeds to + self.controller.shutdown() (the original behavior preserved). + """ + from unittest.mock import MagicMock, patch + import src.gui_2 as gui2_mod + app = MagicMock() + app.runner_params = MagicMock() + app.runner_params.ini_filename = "manualslop_layout.ini" + with patch("src.gui_2.imgui.save_ini_settings_to_disk", side_effect=OSError("disk full")): + result = gui2_mod._shutdown_save_ini_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._shutdown_save_ini_result" + assert "disk full" in err.message + +