{"record":{"id":"9bc2e27dc79c737e","repo":"can1357/oh-my-pi","slug":"file-not-found-path-9bc2e2","errorCode":null,"errorMessage":"File not found: ${path}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/edit/read-file.ts","lineNumber":16,"sourceCode":"/**\n * Shared file-read helper for edit-mode utilities.\n *\n * Reads a file via Bun and rethrows ENOENT as a user-facing \"File not found\"\n * error referencing the display path.\n */\nimport { isEnoent } from \"@oh-my-pi/pi-utils\";\nimport { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from \"./notebook\";\n\nexport async function readEditFileText(absolutePath: string, path: string): Promise<string> {\n\ttry {\n\t\tif (isNotebookPath(absolutePath)) return await readEditableNotebookText(absolutePath, path);\n\t\treturn await Bun.file(absolutePath).text();\n\t} catch (error) {\n\t\tif (isEnoent(error)) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport async function serializeEditFileText(absolutePath: string, path: string, content: string): Promise<string> {\n\tif (isNotebookPath(absolutePath)) return serializeEditedNotebookText(absolutePath, path, content);\n\treturn content;\n}\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/edit/read-file.ts#L1-L26","documentation":"readEditFileText loads the text of a file (or its notebook virtual text) as the base for an edit operation. When the underlying read fails with ENOENT it rethrows a friendly 'File not found' error naming the display path, so callers get a clear message instead of a raw Bun filesystem error.","triggerScenarios":"Calling any edit/read tool (read, rawContent, computeEditDiff, writeText, etc.) with a path that does not exist on disk — typically an edit against a file that was deleted, renamed, or never created, or a path with a typo/wrong working directory.","commonSituations":"Editing a file the agent believes exists but that was removed by a previous operation; typo in path; relative path resolved against the wrong root; race where another process deleted the file between listing and editing.","solutions":["Check the path exists (ls / stat) and correct any typo before editing","Create the file first (use the create/write tool) if the intent was a new file","Re-list the directory to confirm the current file name after refactors or renames","If the path is relative, resolve it against the intended working directory"],"exampleFix":"// before\nawait readEditFileText(abs, 'src/old-name.ts')\n// after\nawait readEditFileText(abs, 'src/new-name.ts') // after verifying via ls","handlingStrategy":"try-catch","validationCode":"const file = Bun.file(absolutePath);\nif (!(await file.exists())) throw new Error(`Refusing edit: ${path} does not exist`);","typeGuard":null,"tryCatchPattern":"try {\n  const text = await readEditFileText(abs, path);\n  // edit...\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('File not found:')) {\n    // recreate, correct path, or surface to user\n  } else throw err;\n}","preventionTips":["Stat or list the file before editing, especially after renames/deletes","Resolve relative paths against the same root the tool uses","Create new files with the write tool before attempting edit operations","Re-read directory contents after refactor operations to confirm names"],"tags":["filesystem","file-not-found","enoent"],"backgroundTag":"file-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}