jackwener/OpenCLI · error · ArgumentError

--keywords is required

Error message

--keywords is required

What it means

After normalizing whitespace, the keywords argument is empty, so the search would be meaningless; the library throws this ArgumentError before issuing the API call. Note that args.keywords is declared required, but a whitespace-only string can still pass the CLI layer and be caught here.

Source

Thrown at clis/linkedin-learning/search.js:66

}

cli({
    site: 'linkedin-learning',
    name: 'search',
    access: 'read',
    description: 'Search LinkedIn Learning courses, videos, and learning paths by keyword',
    domain: DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    args: [
        { name: 'keywords', type: 'string', required: true, positional: true, help: 'Search keywords, e.g. "AI agent"' },
        { name: 'limit', type: 'int', default: 10, help: `Maximum results to return (1-${MAX_LIMIT})` },
    ],
    columns: ['rank', 'type', 'title', 'instructor', 'difficulty', 'duration_sec', 'rating', 'rating_count', 'viewers', 'url'],
    func: async (page, args) => {
        if (!page) throw new CommandExecutionError('Browser session required for linkedin-learning search');
        const keywords = normalizeWhitespace(args.keywords);
        if (!keywords) throw new ArgumentError('--keywords is required');
        const limit = parseLimit(args.limit);

        const url = `https://www.linkedin.com/learning-api/searchV2?keywords=${encodeURIComponent(keywords)}&q=keywords`;
        const result = await fetchLinkedInLearningApi(page, url);
        if (!result?.json) {
            throw new CommandExecutionError(`LinkedIn Learning searchV2 failed: ${result?.error ?? 'no payload'}`);
        }
        const elements = result.json?.elements;
        if (!Array.isArray(elements)) {
            throw new CommandExecutionError('LinkedIn Learning searchV2 returned malformed payload: missing elements array');
        }
        if (elements.length === 0) {
            throw new EmptyResultError(`No LinkedIn Learning results for "${keywords}"`);
        }
        const rows = [];
        for (const el of elements) {
            if (rows.length >= limit) break;
            const row = parseRow(el, rows.length + 1);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide non-empty keywords, e.g. opencli linkedin-learning search 'AI agent'.
  2. Check shell quoting/variable expansion — an empty "$VAR" collapses to nothing; guard before invoking.
  3. In scripts, validate the search term is non-blank before calling the command.

Example fix

// before
KEYWORDS=""
opencli linkedin-learning search "$KEYWORDS"
// after
KEYWORDS="AI agent"
[ -n "$KEYWORDS" ] && opencli linkedin-learning search "$KEYWORDS"
Defensive patterns

Strategy: validation

Validate before calling

const kw = (keywords ?? '').trim();
if (!kw) {
  throw new Error('keywords must be a non-empty string before calling linkedin-learning search');
}

Type guard

function hasKeywords(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await runCommand('linkedin-learning', 'search', [keywords]);
} catch (e) {
  if (e.message.includes('--keywords is required')) {
    // fix upstream quoting/empty variable, then retry with a real term
  } else throw e;
}

Prevention

When it happens

Trigger: Calling linkedin-learning search with keywords = '' or ' ' (whitespace only), or invoking the command programmatically with args.keywords undefined/null so normalizeWhitespace yields an empty string.

Common situations: Shell quoting bugs that drop the quoted argument ('""'); a script variable that is empty/unset; passing an option value into the wrong positional slot; upstream data producing blank search terms.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f82c503d442bfc7a. Report an issue: GitHub.