Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 8: refactor(gui_2): migrate L897 _capture_workspace_profile to Result[T] (Phase 8)
Migrate the imgui.save_ini_settings_to_memory try/except in App._capture_workspace_profile (L897) to the canonical Result[T] pattern: - Extract _capture_workspace_profile_ini_result(app) -> Result[str] helper into Phase 8 Property Setter / State Result Helpers region. - The legacy _capture_workspace_profile method calls the helper and drains errors to app._last_request_errors (per FR-BC-4 event-handler drain pattern; this is a property setter on the App). - The original fallback behavior (ini = '' on failure) is preserved so the legacy WorkspaceProfile still constructs with empty ini_content. Tests: - test_phase_8_l897_capture_workspace_profile_ini_result_success - test_phase_8_l897_capture_workspace_profile_ini_result_failure Audit: INTERNAL_BROAD_CATCH count in src/gui_2.py is now 0. All 22 INTERNAL_BROAD_CATCH sites originally in src/gui_2.py have been migrated to Result[T] across Phases 3-8.
This commit is contained in:
@@ -1553,3 +1553,42 @@ def test_phase_8_l591_diag_layout_state_ini_text_result_failure():
|
||||
assert "permission denied" in err.message
|
||||
assert result.data == ""
|
||||
|
||||
|
||||
def test_phase_8_l897_capture_workspace_profile_ini_result_success():
|
||||
"""
|
||||
L897 _capture_workspace_profile_ini_result returns Result(data=ini_str) on success.
|
||||
|
||||
The helper wraps the imgui.save_ini_settings_to_memory try/except in
|
||||
App._capture_workspace_profile. On success, returns Result(data=ini_str)
|
||||
where ini_str is the serialized INI content. The legacy wrapper drains
|
||||
errors to app._last_request_errors.
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
with patch.object(gui_2.imgui, "save_ini_settings_to_memory", return_value="[Window][Provider]\nPos=10,20"):
|
||||
result = gui_2._capture_workspace_profile_ini_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data == "[Window][Provider]\nPos=10,20"
|
||||
|
||||
|
||||
def test_phase_8_l897_capture_workspace_profile_ini_result_failure():
|
||||
"""
|
||||
L897 _capture_workspace_profile_ini_result returns Result(data="", errors=[ErrorInfo]) on failure.
|
||||
|
||||
When imgui.save_ini_settings_to_memory raises, the helper returns Result
|
||||
with ErrorInfo describing the failure and data="" (matching the original
|
||||
except branch's empty-string fallback).
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
with patch.object(gui_2.imgui, "save_ini_settings_to_memory", side_effect=RuntimeError("imgui backend down")):
|
||||
result = gui_2._capture_workspace_profile_ini_result(app)
|
||||
assert not result.ok, f"Expected ok=False on failure, got data: {result.data}"
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._capture_workspace_profile_ini_result"
|
||||
assert "imgui backend down" in err.message
|
||||
assert result.data == ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user