{"record":{"id":"9b096beba3a286ad","repo":"JuliusBrussee/caveman","slug":"caveman-code-not-a-file-input-path","errorCode":null,"errorMessage":"caveman-code: not a file: ${input.path}","messagePattern":"caveman-code: not a file: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/code.ts","lineNumber":242,"sourceCode":"    containedPath(await workspaceRoot(), candidate);\n\n  const readFileTool = tool({\n    name: \"read_file\",\n    description:\n      \"Read a UTF-8 file from the workspace. Optional offset/limit read a line range. \" +\n      `Output is capped at ${caps.read_file} bytes.`,\n    input: schema.object({\n      path: schema.string(),\n      offset: schema.optional(schema.integer()),\n      limit: schema.optional(schema.integer()),\n    }),\n    effect: \"read\",\n    result: \"inline\",\n    timeoutMs: READ_TIMEOUT_MS,\n    async execute(input) {\n      const target = await contained(input.path);\n      const info = await stat(target);\n      if (!info.isFile()) throw new Error(`caveman-code: not a file: ${input.path}`);\n      const content = await readFile(target, \"utf8\");\n      const lines = content.split(\"\\n\");\n      const offset = Math.max(1, input.offset ?? 1);\n      const limit = input.limit === undefined ? lines.length : Math.max(1, input.limit);\n      const selected = lines.slice(offset - 1, offset - 1 + limit);\n      const numbered = selected\n        .map((line, index) => `${offset + index}\\t${line}`)\n        .join(\"\\n\");\n      const text = capOutput(numbered, caps.read_file);\n      record(`read_file:${input.path}`, text);\n      return text;\n    },\n  });\n\n  const grepTool = tool({\n    name: \"grep\",\n    description:\n      \"Search the workspace for a regular expression with ripgrep (grep fallback). \" +","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/code.ts#L224-L260","documentation":"The read tool in packages/agent/src/code.ts resolves the requested path inside the workspace (contained()), stats it, and requires it to be a regular file. If stat succeeds but the target is a directory, symlink-to-directory, socket, or other non-file, it throws 'caveman-code: not a file: <path>'.","triggerScenarios":"Invoking the read tool with input.path pointing at a directory (e.g. 'src' or '.'), a device/pipe file, or a symlink resolving to a directory; passing a path without the filename when intending to read every file in a folder.","commonSituations":"The LLM/agent passes a directory path hoping for a directory listing; a config variable holding a directory root is reused as a read target; a symlink points at a directory after a refactor; trailing-slash or glob-style paths like 'src/*.ts' are supplied.","solutions":["Pass the full path to a regular file (e.g. src/index.ts), not a directory.","Use the list/glob tool to enumerate directory contents first, then read individual files.","Resolve symlinks: point the read at the actual file the symlink targets.","Strip trailing slashes or glob patterns from the path before calling read.","If you need directory contents, use the codebase search/list tools instead of read."],"exampleFix":"// before\ntool.read({ path: \"src\" })\n// after\ntool.read({ path: \"src/index.ts\" })","handlingStrategy":"validation","validationCode":"const st = await fs.promises.stat(path);\nif (!st.isFile()) throw new Error(`${path} is not a regular file`);","typeGuard":"const isRegularFile = (p: string) =>\n  fs.existsSync(p) && fs.statSync(p).isFile();","tryCatchPattern":"try {\n  await read({ path });\n} catch (e) {\n  if (e.message.startsWith(\"caveman-code: not a file:\")) {\n    const st = await fs.promises.stat(path);\n    if (st.isDirectory()) console.error(`${path} is a directory — list it first, then read files individually`);\n  } else throw e;\n}","preventionTips":["Stat the path before reading; only pass regular files to the read tool.","Resolve symlinks to their final target and verify it is a file.","Use the list/glob tool for directories instead of attempting to read them.","Strip trailing slashes and glob patterns from paths before reading."],"tags":["filesystem","tooling","invalid-argument"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}