CherryHQ/cherry-studio · warning · Error
File not found: ${filePath}
Error message
File not found: ${filePath} What it means
fs.stat rejected with ENOENT and the caller did not request file creation — old_string was non-empty, so the create-file branch (edit.ts:53-71) is skipped and the missing file is reported. The edit tool only auto-creates a file when old_string is exactly ''; any other old_string against a nonexistent file yields this error.
Source
Thrown at src/main/ai/mcp/servers/filesystem/tools/edit.ts:73
const parentDir = path.dirname(validPath)
await fs.mkdir(parentDir, { recursive: true })
// Write the new content
await fs.writeFile(validPath, newString, 'utf-8')
logger.info('File created', { path: validPath })
const relativePath = path.relative(baseDir, validPath)
return {
content: [
{
type: 'text',
text: `Created new file: ${relativePath}\nLines: ${newString.split('\n').length}`
}
]
}
}
throw new Error(`File not found: ${filePath}`)
}
throw error
}
// Read current content
const content = await fs.readFile(validPath, 'utf-8')
// Handle special case: old_string is empty (create file with content)
if (oldString === '') {
await fs.writeFile(validPath, newString, 'utf-8')
logger.info('File overwritten', { path: validPath })
const relativePath = path.relative(baseDir, validPath)
return {
content: [
{
type: 'text',View on GitHub (pinned to 726446b54c)
Solutions
- If creating a new file, set old_string to '' so the edit tool takes the create branch.
- Otherwise, verify the file_path exists with the ls or read tool first.
- Check for trailing whitespace or path-separator differences (e.g. backslash on Windows) that change resolution.
Example fix
// before
throw new Error(`File not found: ${filePath}`)
// after — hint at the create-file convention in the message
throw new Error(`File not found: ${filePath}. To create it, retry with old_string=""`) Defensive patterns
Strategy: validation
Validate before calling
// For creation intent, use the empty-old_string convention; otherwise check existence.
import { stat } from 'fs/promises'
async function fileExists(p: string): Promise<boolean> {
try { await stat(p); return true } catch { return false }
} Prevention
- To create a new file, send old_string:'' to enter the create branch.
- Verify file_path exists (read/ls) before editing an existing file.
- Watch for path-separator and trailing-whitespace differences that change resolution.
- Beware of concurrent deletions between read and edit.
When it happens
Trigger: Editing a file path that does not exist without using the create-on-empty-old_string convention; a typo in file_path; a file deleted between the read and edit calls; a relative path that validatePath resolved to an unexpected location.
Common situations: A model that read a file in a previous turn but the file was since removed; misspelled filenames; attempting to edit a file the model assumed existed because a sibling does.
Related errors
- Path not found: ${targetPath}
- Invalid arguments for edit: ${parsed.error}
- Path is not a file: ${filePath}
- Directory not found: ${validPath}
- Session workspace is unavailable: ${workspaceRoot}
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/e60628a1134de8e2.
Report an issue: GitHub.