Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 5: refactor(gui_2): migrate L1284 _populate_auto_slices outline to Result[T] (Phase 5)
Extract _populate_auto_slices_outline_result helper from the
mcp_client.{py,ts_c,ts_cpp}_get_code_outline try/except in
App._populate_auto_slices. Legacy wrapper drains errors to
app._last_request_errors per FR-BC-4 event-handler pattern.
[pre-audit] L1284 INTERNAL_BROAD_CATCH
[post-audit] V count: 14 -> 13 (L1284 removed)
This commit is contained in:
+40
-10
@@ -1265,23 +1265,20 @@ class App:
|
||||
self.ai_status = 'paths applied and session reset'
|
||||
|
||||
def _populate_auto_slices(self, f_item: models.FileItem) -> None:
|
||||
from src import mcp_client
|
||||
import re
|
||||
from pathlib import Path
|
||||
import os
|
||||
proj_dir = str(Path(self.controller.active_project_path).parent.resolve()) if getattr(self, 'controller', None) and self.controller.active_project_path else None
|
||||
abs_path = f_item.path if os.path.isabs(f_item.path) else os.path.join(proj_dir or '.', f_item.path)
|
||||
mcp_client.configure([{"path": abs_path}], [proj_dir] if proj_dir else None)
|
||||
|
||||
f_path_lower = f_item.path.lower()
|
||||
|
||||
#TODO(Ed): Exception(Review)
|
||||
try:
|
||||
if f_path_lower.endswith('.py'): outline = mcp_client.py_get_code_outline(abs_path)
|
||||
elif f_path_lower.endswith(('.c', '.h')): outline = mcp_client.ts_c_get_code_outline(abs_path)
|
||||
elif f_path_lower.endswith(('.cpp', '.hpp', '.cxx', '.cc')): outline = mcp_client.ts_cpp_get_code_outline(abs_path)
|
||||
else: return
|
||||
except Exception:
|
||||
outline_result = _populate_auto_slices_outline_result(self, f_item, abs_path)
|
||||
if not outline_result.ok:
|
||||
if not hasattr(self, '_last_request_errors'): self._last_request_errors = []
|
||||
self._last_request_errors.append(("_populate_auto_slices.outline", outline_result.errors[0]))
|
||||
return
|
||||
outline = outline_result.data
|
||||
if not outline:
|
||||
return
|
||||
|
||||
if outline.startswith("ERROR") or outline.startswith("ACCESS DENIED"):
|
||||
@@ -7730,4 +7727,37 @@ def _render_ast_inspector_file_content_result(app: "App", f_path: str) -> Result
|
||||
|
||||
#endregion: Phase 4 Modal/Dialog Result Helpers
|
||||
|
||||
#region: Phase 5 Event Handler Result Helpers (result_migration_gui_2_20260619)
|
||||
|
||||
def _populate_auto_slices_outline_result(app: "App", f_item, abs_path: str) -> Result[str]:
|
||||
"""Drain-aware variant of L1284 _populate_auto_slices outline fetch.
|
||||
|
||||
Extracts the mcp_client.{py,ts_c,ts_cpp}_get_code_outline try/except
|
||||
from App._populate_auto_slices into a Result-returning helper. On success
|
||||
(extension matches and outline fetch succeeded), returns
|
||||
Result(data=outline). On "skip" (no matching extension), returns
|
||||
Result(data=""). On exception, returns Result(data="",
|
||||
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._populate_auto_slices (L1284 legacy wrapper)]
|
||||
"""
|
||||
f_path_lower = f_item.path.lower()
|
||||
try:
|
||||
if f_path_lower.endswith('.py'): return Result(data=mcp_client.py_get_code_outline(abs_path))
|
||||
elif f_path_lower.endswith(('.c', '.h')): return Result(data=mcp_client.ts_c_get_code_outline(abs_path))
|
||||
elif f_path_lower.endswith(('.cpp', '.hpp', '.cxx', '.cc')): return Result(data=mcp_client.ts_cpp_get_code_outline(abs_path))
|
||||
else: return Result(data="")
|
||||
except Exception as e:
|
||||
return Result(data="", errors=[ErrorInfo(
|
||||
kind=ErrorKind.INTERNAL,
|
||||
message=f"AST outline fetch failed for {f_item.path}: {e}",
|
||||
source="gui_2._populate_auto_slices_outline_result",
|
||||
original=e,
|
||||
)])
|
||||
|
||||
#endregion: Phase 5 Event Handler Result Helpers
|
||||
|
||||
#endregion: MMA
|
||||
|
||||
Reference in New Issue
Block a user