diff --git a/gptme/tools/patch.py b/gptme/tools/patch.py index 0c46be0e..09cfc2ee 100644 --- a/gptme/tools/patch.py +++ b/gptme/tools/patch.py @@ -159,15 +159,23 @@ def execute_patch( Applies the patch. """ fn = " ".join(args) - assert fn, "No filename provided" + if not fn: + yield Message("system", "No path provided") + return + path = Path(fn).expanduser() if not path.exists(): - raise ValueError(f"file not found: {fn}") + yield Message("system", f"File not found: {fn}") + return - patches = Patch.from_codeblock(code) - patches_str = "\n\n".join(p.diff_minimal() for p in patches) - print_preview(patches_str, lang="diff") + try: + patches = Patch.from_codeblock(code) + patches_str = "\n\n".join(p.diff_minimal() for p in patches) + except ValueError as e: + yield Message("system", f"Patch failed: {e.args[0]}") + return + print_preview(patches_str, lang="diff") if ask: # TODO: display minimal patches confirm = ask_execute(f"Apply patch to {fn}?")