{"record":{"id":"46d3a48015ebdb09","repo":"dmtrKovalenko/fff","slug":"patterns-array-must-have-at-least-1-element","errorCode":null,"errorMessage":"patterns array must have at least 1 element","messagePattern":"patterns array must have at least 1 element","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/pi-fff/src/index.ts","lineNumber":1199,"sourceCode":"      ),\n      cursor: Type.Optional(Type.String({ description: \"Pagination cursor\" })),\n    });\n\n    queueTool(() => toolNames.multiGrep, {\n      description:\n        \"Search file contents for ANY of multiple literal patterns (OR, SIMD Aho-Corasick). Faster than regex alternation.\",\n      promptSnippet: \"Multi-pattern OR content search\",\n      promptGuidelines: (names) => [\n        `${names.multiGrep}: use when searching for several identifiers at once.`,\n        `${names.multiGrep}: include all naming-convention variants (snake/camel/Pascal).`,\n        `${names.multiGrep}: patterns are literal. Use constraints for file filters.`,\n      ],\n      parameters: multiGrepSchema,\n\n      async execute(_toolCallId, params, signal) {\n        if (signal?.aborted) throw new Error(\"Operation aborted\");\n        if (!params.patterns?.length)\n          throw new Error(\"patterns array must have at least 1 element\");\n\n        const f = await ensureFinder(activeCwd);\n        const effectiveLimit = Math.max(1, params.limit ?? DEFAULT_GREP_LIMIT);\n        const pageSize = Math.min(effectiveLimit, GREP_PAGE_SIZE_MAX);\n        const context = clampContext(params.context);\n\n        const grepResult = f.multiGrep({\n          patterns: params.patterns,\n          constraints: params.constraints,\n          maxMatchesPerFile: GREP_MAX_MATCHES_PER_FILE,\n          pageSize,\n          smartCase: true,\n          cursor: (params.cursor ? getCursor(params.cursor) : null) ?? null,\n          beforeContext: context,\n          afterContext: context,\n        });\n\n        if (!grepResult.ok) throw new Error(grepResult.error);","sourceCodeStart":1181,"sourceCodeEnd":1217,"githubUrl":"https://github.com/dmtrKovalenko/fff/blob/7f8537e70f0ea1210f9acbbfc4640141105cdc78/packages/pi-fff/src/index.ts#L1181-L1217","documentation":"multiGrep requires at least one pattern; the tool validates `params.patterns?.length` and throws when the array is missing, null, or empty. This is an explicit input validation guard before hitting the native grep.","triggerScenarios":"Calling multiGrep with `patterns: []`, with `patterns` omitted, or with `patterns: null` (e.g. spread-built param objects that collapsed to empty).","commonSituations":"Dynamically generating pattern lists where all candidates were filtered out; LLM/agent emitting an empty array; template code leaving the patterns slot unfilled.","solutions":["Pass at least one literal pattern in the patterns array","If all patterns were filtered out, skip the call entirely instead of invoking with []","Use the single-pattern grep tool when you only have one pattern","Validate the array length before calling when patterns are generated dynamically"],"exampleFix":"// before\nawait multiGrep.execute(id, { patterns: filteredPatterns }); // [] when nothing matched\n\n// after\nif (filteredPatterns.length > 0) {\n  await multiGrep.execute(id, { patterns: filteredPatterns });\n}","handlingStrategy":"validation","validationCode":"if (!Array.isArray(patterns) || patterns.length === 0) throw new Error('patterns must contain at least 1 element');","typeGuard":"const hasPatterns = (p: unknown): p is { patterns: [string, ...string[]] } =>\n  typeof p === 'object' && p !== null && Array.isArray((p as any).patterns) && (p as any).patterns.length > 0;","tryCatchPattern":"try { await multiGrepTool.execute(id, params, signal); } catch (e) { if (String(e).includes('at least 1 element')) return null; throw e; }","preventionTips":["Check patterns.length before calling","Fall back to single-pattern grep when only one pattern exists","Skip the call entirely when generated pattern lists end up empty"],"tags":["validation","arguments","grep"],"backgroundTag":"empty-required-field","analyzedSha":"7f8537e70f0ea1210f9acbbfc4640141105cdc78","analyzedAt":"2026-09-10T07:26:53.407Z","contentChangedAt":"2026-09-10T07:26:53.407Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}