dmtrKovalenko/fff · error
patterns array must have at least 1 element
Error message
patterns array must have at least 1 element
What it means
multiGrep validates that the patterns option is a non-empty array before crossing the FFI boundary, because the Rust side expects at least one newline-joined pattern. An empty or missing patterns array would produce a useless or unsafe call into the native library, so it is rejected in JS with this error.
Solutions
- Check options.patterns before calling and ensure it contains at least one non-empty pattern
- Skip the multiGrep call entirely (or return an empty result) when the pattern list is empty
- Add a fallback default pattern when the caller's list filters down to zero
Example fix
// before
finder.multiGrep({ patterns: myPatterns, constraints: '' });
// after
if (!myPatterns.length) return;
finder.multiGrep({ patterns: myPatterns.length ? myPatterns : ['*'], constraints: '' }); Defensive patterns
Strategy: validation
Validate before calling
if (!Array.isArray(patterns) || patterns.length === 0) throw new Error('multiGrep needs at least 1 pattern'); Type guard
function hasPatterns(o) { return Array.isArray(o?.patterns) && o.patterns.length > 0; } Try / catch
try { finder.multiGrep(opts); } catch (e) { if (String(e).includes('patterns array')) { /* recover: use fallback pattern or skip */ } } Prevention
- Default pattern lists to a non-empty fallback
- Filter patterns only after checking the filtered result is non-empty
- Unit-test option builders for the empty case
When it happens
Trigger: Calling finder.multiGrep() with no options.patterns, with patterns: [], or with patterns left undefined after building options dynamically.
Common situations: Building the pattern list programmatically from user input or config where filtering removed all patterns; forgetting to default to a fallback pattern list.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- fff native library not found. Run `npx @ff-labs/fff-node…
- Query is null or invalid UTF-8
- File path is null or invalid UTF-8
- Failed to canonicalize path
- Unsupported FffWatchOptions version
AI-assisted analysis of dmtrKovalenko/fff@7f8537e70f (2026-09-10).
Data as JSON: /api/errors/b49b53c1cdf33f99.
Report an issue: GitHub.
Appendix: source
Thrown at packages/fff-bun/src/finder.ts:413
*
* @example
* ```typescript
* const result = finder.multiGrep({
* patterns: ["VideoFrame", "video_frame", "PreloadedImage"],
* });
* if (result.ok) {
* for (const match of result.value.items) {
* console.log(`${match.relativePath}:${match.lineNumber}: ${match.lineContent}`);
* }
* }
* ```
*/
multiGrep(options: MultiGrepOptions): Result<GrepResult> {
const guard = this.ensureAlive();
if (!guard.ok) return guard;
if (!options.patterns || options.patterns.length === 0) {
return err("patterns array must have at least 1 element");
}
return ffiMultiGrep(
guard.value,
options.patterns.join("\n"),
options.constraints ?? "",
options.maxFileSize ?? 0,
options.maxMatchesPerFile ?? 0,
options.smartCase ?? true,
options.cursor?._offset ?? 0,
options.pageSize ?? 0,
options.timeBudgetMs ?? 0,
options.enforceTimeBudget ?? false,
options.beforeContext ?? 0,
options.afterContext ?? 0,
options.classifyDefinitions ?? false,
);
}View on GitHub (pinned to 7f8537e70f)