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 + +