jackwener/OpenCLI · error · ArgumentError
${label} is required
Error message
${label} is required What it means
requireStringArg normalizes whitespace on the named CLI argument and throws ArgumentError if the value is empty or missing. It guarantees downstream query-building code (e.g. Sales Navigator keyword search) always receives a non-empty string.
Source
Thrown at clis/linkedin/salesnav-search.js:20
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { unwrapEvaluateResult } from './shared.js';
const LINKEDIN_DOMAIN = 'www.linkedin.com';
const SALES_HOME = 'https://www.linkedin.com/sales/';
const LEAD_SEARCH_BASE = 'https://www.linkedin.com/sales-api/salesApiLeadSearch';
// Versioned response decoration. LinkedIn bumps this on Sales Navigator
// redeploys; if the response shape ever changes, refresh it from a live
// /sales/search/people request.
const LEAD_SEARCH_DECORATION = 'com.linkedin.sales.deco.desktop.searchv2.LeadSearchResult-14';
const PAGE_SIZE = 25;
function normalizeWhitespace(value) {
return String(value ?? '').replace(/[ ]/g, ' ').replace(/\s+/g, ' ').trim();
}
function requireStringArg(args, key, label = key) {
const value = normalizeWhitespace(args[key]);
if (!value) throw new ArgumentError(`${label} is required`);
return value;
}
function parseLimit(value) {
if (value === undefined || value === null || value === '') return 25;
const limit = Number(value);
if (!Number.isInteger(limit) || limit < 1 || limit > 500) {
throw new ArgumentError('--limit must be an integer between 1 and 500');
}
return limit;
}
// Sales Navigator keeps the structural ( ) , : of the query literal and only
// percent-encodes the keyword value.
function leadSearchUrl(keywords, start) {
const query = '(spellCorrectionEnabled:true,recentSearchParam:(doLogHistory:true),keywords:'
+ encodeURIComponent(keywords) + ')';
return LEAD_SEARCH_BASEView on GitHub (pinned to 49907e53dc)
Solutions
- Pass the required argument, e.g. --keywords "engineer AND sales".
- Echo the shell variable before invoking to confirm it is non-empty.
- Fix the flag name/kebab-case spelling to match the CLI's expected key.
Example fix
// before await run(['salesnav-search']); // missing keywords // after await run(['salesnav-search', '--keywords', 'engineer AND sales']);
Defensive patterns
Strategy: validation
Validate before calling
const keywords = (args.keywords ?? '').replace(/[\u00a0\u202f]/g, ' ').replace(/\s+/g, ' ').trim();
if (!keywords) throw new Error('--keywords is required before invoking the CLI'); Type guard
function hasKeywords(args) {
return typeof args.keywords === 'string' && args.keywords.trim().length > 0;
} Prevention
- Default non-empty keyword values in wrapper scripts
- Validate CLI args in your wrapper before spawning
- Watch for invisible whitespace (nbsp) in copied query strings
- Use set -u / ${VAR:?} in shell scripts to catch unset variables
When it happens
Trigger: Invoking a salesnav-search command without the required argument (e.g. no --keywords), or passing only whitespace/nbsp characters so the normalized value is an empty string.
Common situations: Scripted calls with an unset shell variable (--keywords "$QUERY" where QUERY is empty); users quoting an empty string; typo in the flag name so the expected key is absent from args.
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
- keyword must not be empty
- <from> station must not be empty
- <to> station must not be empty
- who 不能为空
- key is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/b37ed0a64eef4519.
Report an issue: GitHub.