{"record":{"id":"3005fed761eefe93","repo":"dmtrKovalenko/fff","slug":"patterns-array-must-have-at-least-1-element-3005fe","errorCode":null,"errorMessage":"patterns array must have at least 1 element","messagePattern":"patterns array must have at least 1 element","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/fff-node/src/finder.ts","lineNumber":419,"sourceCode":"   *\n   * @example\n   * ```typescript\n   * const result = finder.multiGrep({\n   *   patterns: [\"VideoFrame\", \"video_frame\", \"PreloadedImage\"],\n   * });\n   * if (result.ok) {\n   *   for (const match of result.value.items) {\n   *     console.log(`${match.relativePath}:${match.lineNumber}: ${match.lineContent}`);\n   *   }\n   * }\n   * ```\n   */\n  multiGrep(options: MultiGrepOptions): Result<GrepResult> {\n    const guard = this.ensureAlive();\n    if (!guard.ok) return guard;\n\n    if (!options.patterns || options.patterns.length === 0) {\n      return err(\"patterns array must have at least 1 element\");\n    }\n\n    return ffiMultiGrep(\n      guard.value,\n      options.patterns.join(\"\\n\"),\n      options.constraints ?? \"\",\n      options.maxFileSize ?? 0,\n      options.maxMatchesPerFile ?? 0,\n      options.smartCase ?? true,\n      options.cursor?._offset ?? 0,\n      options.pageSize ?? 0,\n      options.timeBudgetMs ?? 0,\n      options.enforceTimeBudget ?? false,\n      options.beforeContext ?? 0,\n      options.afterContext ?? 0,\n      options.classifyDefinitions ?? false,\n    );\n  }","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/dmtrKovalenko/fff/blob/7f8537e70f0ea1210f9acbbfc4640141105cdc78/packages/fff-node/src/finder.ts#L401-L437","documentation":"multiGrep requires a non-empty patterns array because patterns are joined with newlines and passed to the native multi-pattern grep. An empty array would produce an empty pattern string and a meaningless native call, so the method rejects it up front with this error.","triggerScenarios":"Calling finder.multiGrep({ patterns: [] }) or multiGrep({}) (patterns undefined); building the pattern list dynamically (e.g. from user-selected tags) and passing the result when nothing was selected.","commonSituations":"UI where the user deselects all search terms before running; refactoring code that used single-pattern grep and forgot the array must contain at least one entry; deserialized options where the patterns field was dropped.","solutions":["Check patterns.length > 0 before calling multiGrep and skip the call (return an empty GrepResult) when empty.","Fall back to a single-pattern grep when only one pattern is supplied.","Validate MultiGrepOptions at the API boundary so empty pattern lists never reach the finder.","If an empty selection is valid in your app, treat it as a no-op rather than an error."],"exampleFix":"// before\nconst res = finder.multiGrep({ patterns: selectedTags, constraints });\n// after\nif (selectedTags.length === 0) return { matches: [], truncated: false };\nconst res = finder.multiGrep({ patterns: selectedTags, constraints });","handlingStrategy":"validation","validationCode":"function canMultiGrep(o?: MultiGrepOptions): boolean {\n  return Array.isArray(o?.patterns) && o.patterns.length > 0;\n}","typeGuard":"function hasPatterns(o: MultiGrepOptions): o is MultiGrepOptions & { patterns: [string, ...string[]] } {\n  return Array.isArray(o.patterns) && o.patterns.length > 0;\n}","tryCatchPattern":"const res = finder.multiGrep(opts);\nif (!res.ok && /at least 1 element/.test(res.error)) {\n  return emptyGrepResult(); // treat as no-op\n}","preventionTips":["Default patterns to a non-empty list at the call site.","Return an empty result instead of calling with [].","Validate options at your API boundary.","Use a tuple type [string, ...string[]] to enforce non-empty arrays at compile time."],"tags":["validation","grep","empty-array"],"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"}