From f7b314429161fc878fab2d3d81b046db45bfdbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=82CHES?= Date: Fri, 13 Mar 2026 12:27:28 -0600 Subject: [PATCH] fix: separate access/unlink error handling in delete path (#219) (#222) The delete operation in hashline-edit.ts wrapped both access() and unlink() in a single try/catch. If access succeeded but unlink failed (e.g., permissions), the error was silently swallowed and "Deleted" was falsely reported. Now access and unlink have separate error handling: access failures indicate the file doesn't exist, while unlink failures propagate to the caller. Co-authored-by: Claude Opus 4.6 (1M context) --- packages/pi-coding-agent/src/core/tools/hashline-edit.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/pi-coding-agent/src/core/tools/hashline-edit.ts b/packages/pi-coding-agent/src/core/tools/hashline-edit.ts index cd3a69d95..a1ad76bac 100644 --- a/packages/pi-coding-agent/src/core/tools/hashline-edit.ts +++ b/packages/pi-coding-agent/src/core/tools/hashline-edit.ts @@ -177,15 +177,18 @@ export function createHashlineEditTool(cwd: string, options?: HashlineEditToolOp try { // Handle delete if (deleteFile) { + let fileExists = true; try { await ops.access(absolutePath); - await ops.unlink(absolutePath); } catch { - // File doesn't exist, that's fine for delete + fileExists = false; + } + if (fileExists) { + await ops.unlink(absolutePath); } if (signal) signal.removeEventListener("abort", onAbort); resolve({ - content: [{ type: "text", text: `Deleted ${path}` }], + content: [{ type: "text", text: fileExists ? `Deleted ${path}` : `File not found, nothing to delete: ${path}` }], details: { diff: "" }, }); return;