CherryHQ/cherry-studio · warning · Error
Path is not a directory: ${validPath}
Error message
Path is not a directory: ${validPath} What it means
fs.stat on the glob search path succeeded but stats.isDirectory() is false — the caller pointed glob at a regular file or other non-directory. glob requires a directory to search inside. The validated absolute path appears in the message.
Source
Thrown at src/main/ai/mcp/servers/filesystem/tools/glob.ts:49
- IMPORTANT: Omit the path field for the default directory (don't use "undefined" or "null")`,
inputSchema: z.toJSONSchema(GlobToolSchema)
}
// 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 formatView on GitHub (pinned to 726446b54c)
Solutions
- Pass a directory in the path field (or omit it to use the base directory).
- To match a specific file, use a pattern that targets it (e.g. '**/foo.ts') against the parent directory.
- Run ls on the path first to confirm it is a directory.
Example fix
// before
if (!stats.isDirectory()) {
throw new Error(`Path is not a directory: ${validPath}`)
}
// after — suggest the parent directory
const parent = path.dirname(validPath)
throw new Error(`Path is not a directory: ${validPath}. Did you mean to search in ${parent}?`) Defensive patterns
Strategy: validation
Validate before calling
// Confirm the search path is a directory before globbing.
import { stat } from 'fs/promises'
async function assertIsDir(p: string): Promise<void> {
const s = await stat(p)
if (!s.isDirectory()) throw new Error(`Path is not a directory: ${p}`)
} Prevention
- Pass a directory in the path field, or omit it to use the base directory.
- To target a specific file, use a pattern against its parent directory.
- Run ls on the path first to verify it is a directory.
- Avoid reusing a file path from a previous read/edit as the glob root.
When it happens
Trigger: Passing a file path (e.g. '/src/foo.ts') as glob's path argument instead of a directory, or pointing at a symlink that resolves to a file.
Common situations: A model reusing a file path from a prior read/edit call as the glob search root; confusing the path-to-search with the pattern field.
Related errors
- Path is not a file: ${filePath}
- Invalid arguments for glob: ${parsed.error}
- Directory not found: ${validPath}
- Pattern cannot be empty
- Unknown tool: ${name}
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/f3b8ebcbc8de9428.
Report an issue: GitHub.