{"record":{"id":"4abf3933d9a3d5f7","repo":"CherryHQ/cherry-studio","slug":"invalid-arguments-for-grep-parsed-error","errorCode":null,"errorMessage":"Invalid arguments for grep: ${parsed.error}","messagePattern":"Invalid arguments for grep: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/ai/mcp/servers/filesystem/tools/grep.ts","lineNumber":39,"sourceCode":"  description: `Fast content search tool that works with any codebase size.\n\n- Searches file contents using regular expressions\n- Supports full regex syntax (e.g., \"log.*Error\", \"function\\\\s+\\\\w+\")\n- Filter files by pattern with include (e.g., \"*.js\", \"*.{ts,tsx}\")\n- Returns absolute file paths and line numbers with matching content\n- Results are limited to 100 matches\n- Binary files are automatically skipped\n- Common directories (node_modules, .git, dist) are excluded\n- The path parameter must resolve within the configured workspace root if specified\n- If path is not specified, defaults to the base directory`,\n  inputSchema: z.toJSONSchema(GrepToolSchema)\n}\n\n// Handler implementation\nexport async function handleGrepTool(args: unknown, baseDir: string) {\n  const parsed = GrepToolSchema.safeParse(args)\n  if (!parsed.success) {\n    throw new Error(`Invalid arguments for grep: ${parsed.error}`)\n  }\n\n  const data = parsed.data\n\n  if (!data.pattern) {\n    throw new Error('Pattern is required for grep')\n  }\n\n  const searchPath = data.path || baseDir\n  const validPath = await validatePath(searchPath, baseDir)\n\n  const matches: GrepMatch[] = []\n  let truncated = false\n  let regex: RegExp\n\n  // Build ripgrep arguments\n  const rgArgs: string[] = [\n    '--no-heading',","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/filesystem/tools/grep.ts#L21-L57","documentation":"Zod safeParse on the grep tool's arguments failed. GrepToolSchema requires a string `pattern` and accepts optional `path` and `include` strings. parsed.error lists the failing fields. Returned as an isError tool result by the server-level catch.","triggerScenarios":"The arguments object omits pattern, sends pattern as a non-string, or sends include/path as a non-string. An empty-string pattern passes zod but is caught later at error 316.","commonSituations":"A model calling grep with only include and no pattern; a client sending pattern:null; confusion between the path field and the pattern field.","solutions":["Provide pattern as a non-empty regex string (e.g. 'log.*Error').","If using include, send it as a comma-separated file glob string (e.g. '*.ts,*.tsx').","Read parsed.error to find the failing field."],"exampleFix":"// before\nthrow new Error(`Invalid arguments for grep: ${parsed.error}`)\n\n// after — structured issues\nif (!parsed.success) {\n  const issues = parsed.error.issues.map(i => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; ')\n  throw new Error(`Invalid arguments for grep: ${issues}`)\n}","handlingStrategy":"validation","validationCode":"// Validate grep args on the client.\nfunction isValidGrepArgs(a: unknown): a is { pattern: string; path?: string; include?: string } {\n  if (typeof a !== 'object' || a === null) return false\n  const o = a as any\n  return typeof o.pattern === 'string'\n    && (o.path === undefined || typeof o.path === 'string')\n    && (o.include === undefined || typeof o.include === 'string')\n}","typeGuard":"function isGrepArgs(a: unknown): a is { pattern: string; path?: string; include?: string } {\n  return typeof a === 'object' && a !== null && typeof (a as any).pattern === 'string'\n}","tryCatchPattern":null,"preventionTips":["Always send pattern as a non-empty regex string.","Send include as a comma-separated glob string if filtering by file type.","Generate client types from z.toJSONSchema(GrepToolSchema).","Run safeParse on the client before dispatching."],"tags":["zod","validation","grep","mcp-tool","filesystem"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}