Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3: refactor(mcp_client): migrate L229 search_files to Result[T] (Phase 3 site 2)
Legacy search_files (str) now delegates to search_files_result (Result[str]). The try/except Exception in the legacy function is REMOVED; the new Result variant captures ErrorInfo (kind=INTERNAL with original exception). Audit: mcp_client BC count 39 -> 38.
This commit is contained in:
+8
-24
@@ -198,31 +198,15 @@ def search_files(path: str, pattern: str) -> str:
|
|||||||
"""
|
"""
|
||||||
Search for files matching a glob pattern within path.
|
Search for files matching a glob pattern within path.
|
||||||
pattern examples: '*.py', '**/*.toml', 'src/**/*.rs'
|
pattern examples: '*.py', '**/*.toml', 'src/**/*.rs'
|
||||||
|
|
||||||
|
Thin wrapper over search_files_result; the legacy str shape is preserved
|
||||||
|
for backward compatibility, but the try/except Exception lives in the
|
||||||
|
Result variant (where it can capture ErrorInfo with kind=INTERNAL).
|
||||||
"""
|
"""
|
||||||
p, err = _resolve_and_check(path)
|
resolved = search_files_result(path, pattern)
|
||||||
if err or p is None:
|
if resolved.ok:
|
||||||
return err
|
return resolved.data
|
||||||
if not p.is_dir():
|
return "; ".join(e.ui_message() for e in resolved.errors)
|
||||||
return f"ERROR: not a directory: {path}"
|
|
||||||
try:
|
|
||||||
matches = sorted(p.glob(pattern))
|
|
||||||
if not matches:
|
|
||||||
return f"No files matched '{pattern}' in {path}"
|
|
||||||
lines = [f"Search '{pattern}' in {p}:", ""]
|
|
||||||
count = 0
|
|
||||||
for m in matches:
|
|
||||||
# Blacklist check
|
|
||||||
name = m.name.lower()
|
|
||||||
if name == "history.toml" or name.endswith("_history.toml"):
|
|
||||||
continue
|
|
||||||
rel = m.relative_to(p)
|
|
||||||
kind = "file" if m.is_file() else "dir "
|
|
||||||
lines.append(f" [{kind}] {rel}")
|
|
||||||
count += 1
|
|
||||||
lines.append(f" ({count} match(es))")
|
|
||||||
return "\n".join(lines)
|
|
||||||
except Exception as e:
|
|
||||||
return f"ERROR searching '{path}': {e}"
|
|
||||||
|
|
||||||
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."""
|
||||||
|
|||||||
Reference in New Issue
Block a user