Private
Public Access
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.
This commit is contained in:
+10
-23
@@ -209,29 +209,16 @@ def search_files(path: str, pattern: str) -> str:
|
|||||||
return "; ".join(e.ui_message() for e in resolved.errors)
|
return "; ".join(e.ui_message() for e in resolved.errors)
|
||||||
|
|
||||||
def list_directory(path: str) -> str:
|
def list_directory(path: str) -> str:
|
||||||
"""List entries in a directory. Returns a compact text table."""
|
"""List entries in a directory. Returns a compact text table.
|
||||||
p, err = _resolve_and_check(path)
|
|
||||||
if err or p is None:
|
Thin wrapper over list_directory_result; the legacy str shape is
|
||||||
return err
|
preserved for backward compatibility, but the try/except Exception
|
||||||
if not p.exists(): return f"ERROR: path not found: {path}"
|
lives in the Result variant.
|
||||||
if not p.is_dir(): return f"ERROR: not a directory: {path}"
|
"""
|
||||||
try:
|
resolved = list_directory_result(path)
|
||||||
entries = sorted(p.iterdir(), key=lambda e: (e.is_file(), e.name.lower()))
|
if resolved.ok:
|
||||||
lines = [f"Directory: {p}", ""]
|
return resolved.data
|
||||||
count = 0
|
return "; ".join(e.ui_message() for e in resolved.errors)
|
||||||
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}"
|
|
||||||
|
|
||||||
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."""
|
||||||
|
|||||||
Reference in New Issue
Block a user