jackwener/OpenCLI · error · ArgumentError

<slug> is required

Error message

<slug> is required

What it means

parseSlug normalizes the user-supplied slug/URL argument with normalizeWhitespace and throws ArgumentError if the result is empty. It's the standard 'required argument missing' guard for linkedin-learning course commands, ensuring downstream URL/slug parsing always has a value.

Source

Thrown at clis/linkedin-learning/course.js:10

/**
 * LinkedIn Learning course detail by slug, via /learning-api/courses?q=slug.
 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { DOMAIN, fetchLinkedInLearningApi, normalizeWhitespace } from './shared.js';

function parseSlug(value) {
    const s = normalizeWhitespace(value);
    if (!s) throw new ArgumentError('<slug> is required');
    let slug = s;
    if (/^https?:\/\//i.test(s)) {
        let parsed;
        try {
            parsed = new URL(s);
        } catch {
            throw new ArgumentError(`Invalid LinkedIn Learning URL: "${s}"`);
        }
        const host = parsed.hostname.toLowerCase();
        if (host !== 'linkedin.com' && host !== 'www.linkedin.com') {
            throw new ArgumentError(`Invalid LinkedIn Learning host: "${parsed.hostname}"`);
        }
        const m = parsed.pathname.match(/^\/learning\/([^/?#]+)/);
        if (!m) throw new ArgumentError(`Invalid LinkedIn Learning course URL: "${s}"`);
        slug = m[1];
    } else {
        const m = s.match(/^\/?learning\/([^/?#]+)/);
        slug = m ? m[1] : s;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty course slug or LinkedIn Learning URL to the command.
  2. Check the shell variable actually has a value (echo "$SLUG") before invoking.
  3. Quote the argument if it contains special characters.
  4. Verify command usage with --help and supply the required <slug> positional.

Example fix

// before
run(['linkedin-learning', 'course', slug]); // slug = ''
// after
if (!slug?.trim()) throw new Error('slug required');
run(['linkedin-learning', 'course', slug.trim()]);
Defensive patterns

Strategy: validation

Validate before calling

const slug = (process.argv[3] ?? '').trim();
if (!slug) {
  console.error('usage: linkedin-learning course <slug-or-url>');
  process.exit(2);
}

Type guard

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

Try / catch

try {
  await runCommand(['linkedin-learning', 'course', slug]);
} catch (e) {
  if (e.name === 'ArgumentError' && e.message.includes('is required')) {
    console.error('usage: linkedin-learning course <slug-or-url>');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the course command with an empty string, whitespace-only value, or missing positional argument so normalizeWhitespace(value) yields ''.

Common situations: Shell variable holding the slug was empty/unset; extra quoting consumed the argument; user ran the command with the flag but forgot the value; copy-paste captured only whitespace.

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/13d856247445dcee. Report an issue: GitHub.