From a0908f891548bd1b3f66860d1e951cdb80b7a97f Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 20 Jun 2026 08:33:31 -0400 Subject: [PATCH] TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3: refactor(mcp_client): migrate L451 set_file_slice to Result[T] (Phase 3 site 8) Added set_file_slice_result(Result[str]) inside the Result Variants region. Legacy set_file_slice (str) now delegates to set_file_slice_result. Audit: mcp_client BC count 33 -> 32 (Batch A complete: -8 sites). --- src/mcp_client.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/mcp_client.py b/src/mcp_client.py index bcc40bcc..27f09aea 100644 --- a/src/mcp_client.py +++ b/src/mcp_client.py @@ -456,25 +456,16 @@ def get_file_slice(path: str, start_line: int, end_line: int) -> str: return "; ".join(e.ui_message() for e in resolved.errors) def set_file_slice(path: str, start_line: int, end_line: int, new_content: str) -> str: - """Replace a specific line range in a file with new content.""" - p, err = _resolve_and_check(path) - if err: - return err - assert p is not None - if not p.exists(): - return f"ERROR: file not found: {path}" - try: - lines = p.read_text(encoding="utf-8").splitlines(keepends=True) - start_idx = start_line - 1 - end_idx = end_line - if new_content and not new_content.endswith("\n"): - new_content += "\n" - new_lines = new_content.splitlines(keepends=True) if new_content else [] - lines[start_idx:end_idx] = new_lines - p.write_text("".join(lines), encoding="utf-8") - return f"Successfully updated lines {start_line}-{end_line} in {path}" - except Exception as e: - return f"ERROR updating slice in '{path}': {e}" + """Replace a specific line range in a file with new content. + + Thin wrapper over set_file_slice_result; the legacy str shape is + preserved for backward compatibility, but the try/except Exception + lives in the Result variant. + """ + resolved = set_file_slice_result(path, start_line, end_line, new_content) + if resolved.ok: + return resolved.data + return "; ".join(e.ui_message() for e in resolved.errors) def get_git_diff(path: str, base_rev: str = "HEAD", head_rev: str = "") -> str: """