jackwener/OpenCLI · error · ArgumentError
facebook search requires a non-empty query
Error message
facebook search requires a non-empty query
What it means
ArgumentError thrown by requireQuery when the search query is missing, empty, or whitespace-only. requireQuery trims String(value ?? '') and rejects falsy results before the search runs. It is a local input validation guard raised before any browser navigation.
Source
Thrown at clis/facebook/search.js:17
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
const FACEBOOK_HOME = 'https://www.facebook.com';
const MAX_LIMIT = 50;
function requireLimit(value) {
const n = Number(value);
if (!Number.isInteger(n) || n < 1 || n > MAX_LIMIT) {
throw new ArgumentError(`facebook search --limit must be an integer between 1 and ${MAX_LIMIT}`);
}
return n;
}
function requireQuery(value) {
const q = String(value ?? '').trim();
if (!q) throw new ArgumentError('facebook search requires a non-empty query');
return q;
}
function unwrapBrowserResult(value) {
if (value && typeof value === 'object' && 'data' in value) return value.data;
return value;
}
// Modern facebook.com /search/top renders results inside [role="feed"] as
// entity/content links (people, pages, groups, posts) — [role="article"] /
// [role="listitem"] no longer wrap them — and FB seeds scrambled hidden-char
// decoy links back to /search/top. Collect anchors inside the feed, keep only
// real entity/content hrefs, and drop the decoys plus obfuscated text. See #2090.
function buildSearchExtractScript(limit) {
return `(() => {
const limit = ${limit};
function clean(value) {View on GitHub (pinned to 49907e53dc)
Solutions
- Supply a non-empty query, e.g. facebook search --query "openai"
- Trim and check the value before invoking: if (!q?.trim()) return early
- Fix shell quoting so the argument is actually passed
Example fix
// before
const q = process.env.QUERY; // may be undefined
await cli.search({ query: q });
// after
const q = (process.env.QUERY ?? '').trim();
if (!q) throw new Error('QUERY is required');
await cli.search({ query: q }); Defensive patterns
Strategy: validation
Validate before calling
const q = (rawQuery ?? '').trim();
if (!q) throw new Error('A non-empty search query is required');
await cli.search({ query: q }); Type guard
function hasQuery(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await cli.search({ query });
} catch (err) {
if (/requires a non-empty query/.test(err.message)) {
console.error('Usage: facebook search --query "<terms>"');
process.exitCode = 2;
return;
}
throw err;
} Prevention
- Trim and check user-supplied queries before invoking
- Beware shell quoting: "" passes an empty string
- Default or prompt for a query in scripts instead of passing undefined
When it happens
Trigger: Running `facebook search` with no --query argument, an empty string (--query ""), or a value consisting only of whitespace.
Common situations: Scripting where the query variable is empty or null; shell quoting issues dropping the argument; user forgetting the required flag.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- --limit must be a positive integer, got ${JSON.stringify(kwa
- `endoflife ${label} must be <= ${maxValue}`
- facebook search --limit must be an integer between 1 and ${M
- ${label} must be a path/URL or a JSON array: ${errorMessage(
- ${name} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6116393377be84cb.
Report an issue: GitHub.