CherryHQ/cherry-studio · warning · Error

Pattern cannot be empty

Error message

Pattern cannot be empty

What it means

After zod parsing succeeds, the handler trims pattern and checks for an empty string — a pattern of '' or whitespace-only passes zod (because z.string() allows '') but cannot match anything in ripgrep. This is a semantic validation layered on top of the schema check, so the client gets a clear message rather than a confusing 'No files found'.

Source

Thrown at src/main/ai/mcp/servers/filesystem/tools/glob.ts:61

  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',
    `--glob=${pattern}`,
    '--glob=!.git/*',
    '--glob=!node_modules/*',
    '--glob=!dist/*',
    '--glob=!build/*',
    '--glob=!__pycache__/*',
    validPath
  ]

View on GitHub (pinned to 726446b54c)

Solutions

  1. Send a concrete glob pattern such as '*' (all files), '**/*.ts', or 'src/**/*.js'.
  2. Ensure the pattern field is populated by the caller before the request is dispatched.

Example fix

// before
const pattern = parsed.data.pattern.trim()
if (!pattern) {
  throw new Error('Pattern cannot be empty')
}

// after — default to '*' for 'all files' intent, if that matches product semantics
const pattern = parsed.data.pattern.trim() || '*'
if (!pattern) {
  throw new Error('Pattern cannot be empty')
}
Defensive patterns

Strategy: validation

Validate before calling

// Reject empty/whitespace patterns before dispatching.
function isNonEmptyPattern(p: unknown): boolean {
  return typeof p === 'string' && p.trim().length > 0
}

Prevention

When it happens

Trigger: The caller sends pattern as '' or as a string of only spaces/tabs. zod accepts it; this guard rejects it after trimming.

Common situations: A model sending an empty pattern expecting it to mean 'all files' (it should use '*' instead); a templating bug that strips the pattern before sending; trimming whitespace from user input that was entirely whitespace.

Related errors


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