Private
Public Access
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user