From 897fdaba3616005df0d2ea5c56f8ef89424e8ab3 Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Tue, 17 Nov 2026 01:02:32 -0600 Subject: [PATCH] refactor(core): let permission errors from Code Mode fs through as core reports them --- packages/core/src/codemode/fs.ts | 12 ------------ packages/core/test/tool-execute.test.ts | 8 +++----- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/core/src/codemode/fs.ts b/packages/core/src/codemode/fs.ts index 5856e9ba60f..504a835ad76 100644 --- a/packages/core/src/codemode/fs.ts +++ b/packages/core/src/codemode/fs.ts @@ -11,7 +11,6 @@ import { Environment } from "../environment/index.js" import { FileAccess } from "../file-access.js" import { FileWrite } from "../file-write.js" import { Location } from "../location.js" -import { Permission } from "../permission.js" import { fileDiff } from "../tool/plugin/file-diff.js" import { CodeModeExecution } from "./execution.js" @@ -446,17 +445,6 @@ const nodeError = (error: unknown, syscall: string, file: string) => { path: file, }) if (error instanceof Environment.Failed && error.cause instanceof Error) return error.cause - // A denial carries Node's EACCES, so a program can tell it from a missing file. The feedback is the user talking to - // the model, so it must reach the program as the error's message. - if (error instanceof Permission.BlockedError || error instanceof Permission.CorrectedError) - return Object.assign( - new Error( - error instanceof Permission.CorrectedError - ? `The user rejected ${syscall} ${file}: ${error.feedback}` - : `EACCES: ${error.message}, ${syscall} '${file}'`, - ), - { code: "EACCES", errno: -os.errno.EACCES, syscall, path: file }, - ) return error } diff --git a/packages/core/test/tool-execute.test.ts b/packages/core/test/tool-execute.test.ts index e557cda5450..4af5cd9c827 100644 --- a/packages/core/test/tool-execute.test.ts +++ b/packages/core/test/tool-execute.test.ts @@ -543,7 +543,7 @@ describe("fs", () => { createCodeMode(new Map(), permissionService(denyEdits), fileServices(tmp.path, denyEdits)).execute( { code: `let thrown - try { fs.writeFileSync("a.txt", "x") } catch (e) { thrown = [e.message, e.code] } + try { fs.writeFileSync("a.txt", "x") } catch (e) { thrown = [e.message] } const [rejected] = await Promise.allSettled([fs.promises.writeFile("b.txt", "x")]) return [thrown, rejected.status, fs.existsSync("a.txt")]`, }, @@ -553,8 +553,6 @@ describe("fs", () => { const [thrown, status, exists] = JSON.parse(result.output.output) expect(thrown[0]).toContain("Permission denied") - // EACCES, as Node reports a denied file, so a program can tell it from ENOENT. - expect(thrown[1]).toBe("EACCES") expect([status, exists]).toEqual(["rejected", false]) expect(await fs.readdir(tmp.path)).toEqual([]) }) @@ -741,7 +739,7 @@ describe("fs", () => { createCodeMode(new Map(), permissionService(denyOutside), fileServices(tmp.path, denyOutside)).execute( { code: `fs.writeFileSync("a.txt", "a") - const code = (run) => { try { run(); return "ok" } catch (e) { return e.code } } + const code = (run) => { try { run(); return "ok" } catch (e) { return e.message } } return [ code(() => fs.rmSync(${at("here.txt")})), code(() => fs.rmSync(${at("missing.txt")}, { force: true })), @@ -756,7 +754,7 @@ describe("fs", () => { ) // Every call fails the same way whether or not the outside path exists, and nothing outside changed. - expect(JSON.parse(result.output.output)).toEqual(["EACCES", "EACCES", "EACCES", "EACCES", "EACCES", "EACCES"]) + expect(JSON.parse(result.output.output)).toEqual(Array(6).fill("Permission denied: external_directory")) expect(await Bun.file(path.join(outside.path, "here.txt")).text()).toBe("x") }) })