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
- Pass a non-empty course slug or LinkedIn Learning URL to the command.
- Check the shell variable actually has a value (echo "$SLUG") before invoking.
- Quote the argument if it contains special characters.
- 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
- Check shell variables are non-empty before interpolating into commands.
- Quote arguments to avoid whitespace collapse.
- Print usage help when a positional argument is absent.
- Trim inputs before passing to CLI commands.
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
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- dblp ${label} must be a positive integer
- dblp ${label} must be <= ${maxValue}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/13d856247445dcee.
Report an issue: GitHub.