{"record":{"id":"87086b64e4217607","repo":"can1357/oh-my-pi","slug":"file-not-found-filepath","errorCode":null,"errorMessage":"File not found: ${filePath}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/lsp/utils.ts","lineNumber":719,"sourceCode":"\t\tif (!symbolSpec) {\n\t\t\treturn firstNonWhitespaceColumn(targetLine);\n\t\t}\n\n\t\tconst { symbol, occurrence } = parseSymbolSpec(symbolSpec);\n\t\tconst exactIndexes = findSymbolMatchIndexes(targetLine, symbol);\n\t\tconst fallbackIndexes = exactIndexes.length > 0 ? exactIndexes : findSymbolMatchIndexes(targetLine, symbol, true);\n\t\tif (fallbackIndexes.length === 0) {\n\t\t\tthrow new Error(`Symbol \"${symbol}\" not found on line ${lineNumber}`);\n\t\t}\n\t\tif (occurrence > fallbackIndexes.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Symbol \"${symbol}\" occurrence ${occurrence} is out of bounds on line ${lineNumber} (found ${fallbackIndexes.length})`,\n\t\t\t);\n\t\t}\n\t\treturn fallbackIndexes[occurrence - 1];\n\t} catch (error) {\n\t\tif (isEnoent(error)) {\n\t\t\tthrow new Error(`File not found: ${filePath}`);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport async function readLocationContext(filePath: string, line: number, contextLines = 1): Promise<string[]> {\n\tconst targetLine = Math.max(1, line);\n\tconst surrounding = Math.max(0, contextLines);\n\ttry {\n\t\tconst fileText = await Bun.file(filePath).text();\n\t\tconst lines = fileText.split(\"\\n\");\n\t\tif (lines.length === 0) return [];\n\n\t\tconst startLine = Math.max(1, targetLine - surrounding);\n\t\tconst endLine = Math.min(lines.length, targetLine + surrounding);\n\t\tconst context: string[] = [];\n\t\tfor (let currentLine = startLine; currentLine <= endLine; currentLine++) {\n\t\t\tconst content = lines[currentLine - 1] ?? \"\";","sourceCodeStart":701,"sourceCodeEnd":737,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/lsp/utils.ts#L701-L737","documentation":"resolveSymbolColumn wraps its file read in try/catch; when the read fails with ENOENT (file does not exist), it rethrows as a plain, human-readable 'File not found' error naming the path instead of leaking the raw filesystem error.","triggerScenarios":"Calling any LSP tool action with a `file` path that does not exist on disk (after resolving relative to the project dir) — the readLocationContext/resolveSymbolColumn read hits ENOENT.","commonSituations":"Typos or wrong relative paths in tool params; file deleted or renamed after the agent read the plan; paths expressed against the wrong working directory (e.g. repo root vs package dir); Windows/POSIX path separator confusion.","solutions":["Verify the file exists at the given path and pass an absolute or project-relative path that resolves correctly.","Re-check for recent renames/deletes (git status) and update the path.","Run the tool from the correct working directory or pass a path relative to the project root."],"exampleFix":"// before\nawait lspTool.execute({ action: \"hover\", file: \"src/a.ts\", line: 3 }); // wrong cwd\n// after\nawait lspTool.execute({ action: \"hover\", file: \"packages/app/src/a.ts\", line: 3 });","handlingStrategy":"validation","validationCode":"import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nasync function assertFileExists(p: string) {\n  const abs = path.resolve(p);\n  await fs.access(abs, fs.constants.R_OK);\n  return abs;\n}\n// await assertFileExists(params.file) before calling the tool","typeGuard":null,"tryCatchPattern":"try {\n  return await lspTool.execute({ action: \"hover\", file, line });\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"File not found:\")) {\n    // resolve against project root or prompt user for correct path\n    return lspTool.execute({ action: \"hover\", file: path.join(projectRoot, file), line });\n  } throw err;\n}","preventionTips":["Validate file paths against the project root before calling LSP tools.","Use absolute paths or paths verified to exist to avoid cwd ambiguity.","Refresh paths after renames/deletes (check git status)."],"tags":["lsp","filesystem","file-not-found","validation"],"backgroundTag":"file-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}