CherryHQ/cherry-studio · warning · Error
Directory not found: ${validPath}
Error message
Directory not found: ${validPath} What it means
fs.stat on the glob search directory rejected with ENOENT — the validated path resolves inside the workspace root but does not exist on disk. Uses a type-narrowed catch (`'code' in error && error.code === 'ENOENT'`) rather than the `any`-cast pattern used elsewhere.
Source
Thrown at src/main/ai/mcp/servers/filesystem/tools/glob.ts:53
// Handler implementation
export async function handleGlobTool(args: unknown, baseDir: string) {
const parsed = GlobToolSchema.safeParse(args)
if (!parsed.success) {
throw new Error(`Invalid arguments for glob: ${parsed.error}`)
}
const searchPath = parsed.data.path || baseDir
const validPath = await validatePath(searchPath, baseDir)
// Verify the search directory exists
try {
const stats = await fs.stat(validPath)
if (!stats.isDirectory()) {
throw new Error(`Path is not a directory: ${validPath}`)
}
} catch (error: unknown) {
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
throw new Error(`Directory not found: ${validPath}`)
}
throw error
}
// Validate pattern
const pattern = parsed.data.pattern.trim()
if (!pattern) {
throw new Error('Pattern cannot be empty')
}
const files: FileInfo[] = []
let truncated = false
// Build ripgrep arguments for file listing using --glob=pattern format
const rgArgs: string[] = [
'--files',
'--follow',
'--hidden',View on GitHub (pinned to 726446b54c)
Solutions
- Omit the path argument to fall back to the base directory, which is guaranteed to exist (ensureBaseDir creates it in the constructor).
- List the parent directory with ls to discover the correct subdirectory name.
- If the workspace root itself is missing, confirm application.getPath('feature.mcp.workspace') returns a writable location.
Example fix
// before
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
throw new Error(`Directory not found: ${validPath}`)
}
// after — suggest the base directory fallback
throw new Error(`Directory not found: ${validPath}. Omit 'path' to search the base directory ${baseDir}.`) Defensive patterns
Strategy: validation
Validate before calling
// Confirm the search directory exists, or fall back to base.
import { stat } from 'fs/promises'
async function resolveSearchDir(p: string | undefined, baseDir: string): Promise<string> {
const dir = p ?? baseDir
try { await stat(dir) } catch { throw new Error(`Directory not found: ${dir}`) }
return dir
} Prevention
- Omit path to use the guaranteed-to-exist base directory.
- List the parent directory to discover the correct subdirectory name.
- Ensure the workspace root is created at server boot (ensureBaseDir).
- Use absolute paths to avoid resolution ambiguity.
When it happens
Trigger: The caller passed a path argument that points at a directory which has never existed or was removed; a typo in the directory name; the workspace root has not been created yet.
Common situations: A model guessing a directory layout that does not match the actual tree; a freshly initialized workspace where the feature directory has not been scaffolded.
Related errors
- Path not found: ${targetPath}
- File not found: ${filePath}
- Invalid arguments for glob: ${parsed.error}
- Path is not a directory: ${validPath}
- Pattern cannot be empty
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/5ea0ab30817faa5a.
Report an issue: GitHub.