TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 5: refactor(gui_2): migrate L1393 _open_patch_in_external_editor to Result[T] (Phase 5)

Extract _open_patch_in_external_editor_result helper from the external editor
launch try/except in App._open_patch_in_external_editor. Legacy wrapper
drains errors to app._last_request_errors per FR-BC-4 event-handler pattern.

[pre-audit] L1393 INTERNAL_BROAD_CATCH
[post-audit] V count: 11 -> 10 (L1393 removed)
This commit is contained in:
ed
2026-06-19 23:45:29 -04:00
parent 374866619d
commit 77a48b18bf
2 changed files with 120 additions and 23 deletions
+68 -23
View File
@@ -1357,29 +1357,10 @@ class App:
def _open_patch_in_external_editor(self) -> None:
self._external_editor_clicked = True
try:
from src.external_editor import get_default_launcher, create_temp_modified_file
import os
if not self._pending_patch_files:
self._patch_error_message = "No files to edit"
return
launcher = get_default_launcher(self.config)
editor = launcher.config.get_default()
if not editor:
self._patch_error_message = "No external editor configured"
return
original_path = self._pending_patch_files[0]
if not os.path.exists(original_path):
self._patch_error_message = f"Original file not found: {original_path}"
return
temp_path = create_temp_modified_file(self._pending_patch_text)
result = launcher.launch_diff(None, original_path, temp_path)
if result is None: self._patch_error_message = "Failed to launch external editor"
else:
self._patch_error_message = None
self._vscode_diff_process = result
except Exception as e:
self._patch_error_message = str(e)
ext_result = _open_patch_in_external_editor_result(self)
if not ext_result.ok:
if not hasattr(self, '_last_request_errors'): self._last_request_errors = []
self._last_request_errors.append(("_open_patch_in_external_editor", ext_result.errors[0]))
def _reorder_ticket(self, src_idx: int, dst_idx: int) -> None:
if src_idx == dst_idx: return
@@ -7818,6 +7799,70 @@ def _apply_pending_patch_result(app: "App") -> Result[bool]:
original=e,
)])
def _open_patch_in_external_editor_result(app: "App") -> Result[bool]:
"""Drain-aware variant of L1393 _open_patch_in_external_editor.
Extracts the external editor launch try/except from
App._open_patch_in_external_editor into a Result-returning helper. On
success (launcher.launch_diff returns a process), sets
app._patch_error_message=None, app._vscode_diff_process=result and returns
Result(data=True). On failure (launch returns None or raises), sets
app._patch_error_message and returns Result(data=False, errors=[ErrorInfo]).
The legacy wrapper drains errors to app._last_request_errors (per FR-BC-4
event-handler drain pattern; data plane attribute).
[C: src/gui_2.py:App._open_patch_in_external_editor (L1393 legacy wrapper)]
"""
from src.external_editor import get_default_launcher, create_temp_modified_file
import os
try:
if not app._pending_patch_files:
app._patch_error_message = "No files to edit"
return Result(data=False, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message="No files to edit",
source="gui_2._open_patch_in_external_editor_result",
)])
launcher = get_default_launcher(app.config)
editor = launcher.config.get_default()
if not editor:
app._patch_error_message = "No external editor configured"
return Result(data=False, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message="No external editor configured",
source="gui_2._open_patch_in_external_editor_result",
)])
original_path = app._pending_patch_files[0]
if not os.path.exists(original_path):
app._patch_error_message = f"Original file not found: {original_path}"
return Result(data=False, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message=f"Original file not found: {original_path}",
source="gui_2._open_patch_in_external_editor_result",
)])
temp_path = create_temp_modified_file(app._pending_patch_text)
result = launcher.launch_diff(None, original_path, temp_path)
if result is None:
app._patch_error_message = "Failed to launch external editor"
return Result(data=False, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message="Failed to launch external editor",
source="gui_2._open_patch_in_external_editor_result",
)])
app._patch_error_message = None
app._vscode_diff_process = result
return Result(data=True)
except Exception as e:
app._patch_error_message = str(e)
return Result(data=False, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message=f"Open patch in external editor failed: {e}",
source="gui_2._open_patch_in_external_editor_result",
original=e,
)])
#endregion: Phase 5 Event Handler Result Helpers
#endregion: MMA