TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3: refactor(mcp_client): migrate L266 read_file to Result[T] (Phase 3 site 4)

Legacy read_file (str) now delegates to read_file_result (Result[str]).
The try/except Exception is REMOVED.

Audit: mcp_client BC count 37 -> 36.
This commit is contained in:
ed
2026-06-20 08:29:16 -04:00
parent dc41cb3775
commit da9c5419ef
+10 -10
View File
@@ -221,16 +221,16 @@ def list_directory(path: str) -> str:
return "; ".join(e.ui_message() for e in resolved.errors) return "; ".join(e.ui_message() for e in resolved.errors)
def read_file(path: str) -> str: def read_file(path: str) -> str:
"""Return the UTF-8 content of a file, or an error string.""" """Return the UTF-8 content of a file, or an error string.
p, err = _resolve_and_check(path)
if err or p is None: Thin wrapper over read_file_result; the legacy str shape is preserved
return err for backward compatibility, but the try/except Exception lives in
if not p.exists(): return f"ERROR: file not found: {path}" the Result variant.
if not p.is_file(): return f"ERROR: not a file: {path}" """
try: resolved = read_file_result(path)
return p.read_text(encoding="utf-8") if resolved.ok:
except Exception as e: return resolved.data
return f"ERROR reading '{path}': {e}" return "; ".join(e.ui_message() for e in resolved.errors)
#region: Result Variants #region: Result Variants
def _resolve_and_check_result(raw_path: str) -> Result[Path]: def _resolve_and_check_result(raw_path: str) -> Result[Path]: