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 format

View on GitHub (pinned to 726446b54c)

Solutions

  1. Pass a directory in the path field (or omit it to use the base directory).
  2. To match a specific file, use a pattern that targets it (e.g. '**/foo.ts') against the parent directory.
  3. 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

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


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/f3b8ebcbc8de9428. Report an issue: GitHub.