TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 5: refactor(gui_2): migrate L1293 _populate_auto_slices file_read to Result[T] (Phase 5)
Extract _populate_auto_slices_file_read_result helper from the file read 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] L1293 INTERNAL_BROAD_CATCH [post-audit] V count: 13 -> 12 (L1293 removed)
This commit is contained in:
+31
-4
@@ -1284,11 +1284,12 @@ class App:
|
||||
if outline.startswith("ERROR") or outline.startswith("ACCESS DENIED"):
|
||||
return
|
||||
pattern = re.compile(r'^\s*\[(.*?)\] (.*?) \(Lines (\d+)-(\d+)\)', re.MULTILINE)
|
||||
try:
|
||||
with open(f_item.path, "r", encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
except Exception:
|
||||
file_read_result = _populate_auto_slices_file_read_result(self, f_item)
|
||||
if not file_read_result.ok:
|
||||
if not hasattr(self, '_last_request_errors'): self._last_request_errors = []
|
||||
self._last_request_errors.append(("_populate_auto_slices.file_read", file_read_result.errors[0]))
|
||||
return
|
||||
text = file_read_result.data
|
||||
#TODO(Ed): Exception(Review)
|
||||
try:
|
||||
from src.fuzzy_anchor import FuzzyAnchor
|
||||
@@ -7758,6 +7759,32 @@ def _populate_auto_slices_outline_result(app: "App", f_item, abs_path: str) -> R
|
||||
original=e,
|
||||
)])
|
||||
|
||||
|
||||
def _populate_auto_slices_file_read_result(app: "App", f_item) -> Result[str]:
|
||||
"""Drain-aware variant of L1293 _populate_auto_slices file read.
|
||||
|
||||
Extracts the file read try/except from App._populate_auto_slices into a
|
||||
Result-returning helper. On success, returns Result(data=content) where
|
||||
content is the file text. On exception (file not found, encoding error,
|
||||
permission denied), 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 (L1293 legacy wrapper)]
|
||||
"""
|
||||
try:
|
||||
with open(f_item.path, "r", encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
return Result(data=text)
|
||||
except Exception as e:
|
||||
return Result(data="", errors=[ErrorInfo(
|
||||
kind=ErrorKind.INTERNAL,
|
||||
message=f"File read failed for {f_item.path}: {e}",
|
||||
source="gui_2._populate_auto_slices_file_read_result",
|
||||
original=e,
|
||||
)])
|
||||
|
||||
#endregion: Phase 5 Event Handler Result Helpers
|
||||
|
||||
#endregion: MMA
|
||||
|
||||
Reference in New Issue
Block a user