From dc41cb3775dceafe0e20fb5746ed647c092cdfff Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 20 Jun 2026 08:28:38 -0400 Subject: [PATCH] TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3: refactor(mcp_client): migrate L254 list_directory to Result[T] (Phase 3 site 3) Legacy list_directory (str) now delegates to list_directory_result (Result[str]). The try/except Exception is REMOVED. Audit: mcp_client BC count 38 -> 37. --- src/mcp_client.py | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/mcp_client.py b/src/mcp_client.py index a79f7032..e2d39a66 100644 --- a/src/mcp_client.py +++ b/src/mcp_client.py @@ -209,29 +209,16 @@ def search_files(path: str, pattern: str) -> str: return "; ".join(e.ui_message() for e in resolved.errors) def list_directory(path: str) -> str: - """List entries in a directory. Returns a compact text table.""" - p, err = _resolve_and_check(path) - if err or p is None: - return err - if not p.exists(): return f"ERROR: path not found: {path}" - if not p.is_dir(): return f"ERROR: not a directory: {path}" - try: - entries = sorted(p.iterdir(), key=lambda e: (e.is_file(), e.name.lower())) - lines = [f"Directory: {p}", ""] - count = 0 - for entry in entries: - # Blacklist check - name = entry.name.lower() - if name == "history.toml" or name.endswith("_history.toml"): - continue - kind = "file" if entry.is_file() else "dir " - size = f"{entry.stat().st_size:>10,} bytes" if entry.is_file() else "" - lines.append(f" [{kind}] {entry.name:<40} {size}") - count += 1 - lines.append(f" ({count} entries)") - return "\n".join(lines) - except Exception as e: - return f"ERROR listing '{path}': {e}" + """List entries in a directory. Returns a compact text table. + + Thin wrapper over list_directory_result; the legacy str shape is + preserved for backward compatibility, but the try/except Exception + lives in the Result variant. + """ + resolved = list_directory_result(path) + if resolved.ok: + return resolved.data + return "; ".join(e.ui_message() for e in resolved.errors) def read_file(path: str) -> str: """Return the UTF-8 content of a file, or an error string."""