jackwener/OpenCLI · error · ArgumentError

${label} is required

Error message

${label} is required

What it means

requireStringArg normalizes whitespace on args[key] and throws ArgumentError when the resulting value is empty or missing. It guarantees required CLI arguments are present before command logic runs.

Source

Thrown at clis/linkedin/shared.js:107

  let parsed;
  try {
    parsed = new URL(raw, 'https://www.linkedin.com');
  } catch {
    throw new ArgumentError(`${label} must be a LinkedIn URL`);
  }
  const host = parsed.hostname.toLowerCase();
  if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port) {
    throw new ArgumentError(`${label} must be an https LinkedIn URL without credentials or port`);
  }
  if (host !== 'linkedin.com' && host !== 'www.linkedin.com') {
    throw new ArgumentError(`${label} must point to linkedin.com`);
  }
  return parsed.toString();
}

export function requireStringArg(args, key, label = key) {
  const value = normalizeWhitespace(args?.[key]);
  if (!value) throw new ArgumentError(`${label} is required`);
  return value;
}

export function parseLimit(value, fallback, max) {
  if (value === undefined || value === null || value === '') return fallback;
  const parsed = Number(value);
  if (!Number.isInteger(parsed) || parsed < 1 || parsed > max) {
    throw new ArgumentError(`--limit must be an integer between 1 and ${max}`);
  }
  return parsed;
}

export async function requireLinkedInCookie(page, context) {
  let cookies;
  try {
    cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
  } catch (error) {
    throw new CommandExecutionError(`LinkedIn cookie lookup failed: ${error?.message || error}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the required argument: e.g. `--url "https://www.linkedin.com/in/some-profile/"`.
  2. Check the label in the error — it tells you which key was missing (label defaults to the key name).
  3. If sourcing from an env var, verify it is set and non-empty before invoking: `${MY_URL:?MY_URL is required}`.
  4. Trim the value; whitespace-only strings are rejected.

Example fix

// before
await url({ url: process.env.PROFILE_URL || '' });
// after
if (!process.env.PROFILE_URL) throw new Error('PROFILE_URL is required');
await url({ url: process.env.PROFILE_URL });
Defensive patterns

Strategy: validation

Validate before calling

if (!args?.url || !String(args.url).trim()) {
  throw new Error('--url is required');
}

Type guard

function hasArg(args, key) {
  return typeof args?.[key] === 'string' && args[key].trim().length > 0;
}

Try / catch

try {
  await runCommand(args);
} catch (e) {
  if (e instanceof ArgumentError && / is required$/.test(e.message)) {
    console.error(`Missing required argument: ${e.message.replace(' is required', '')}`);
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking a command without the required flag, or passing it as an empty/whitespace-only string, e.g. `linkedin url --url ""` or omitting --url entirely.

Common situations: Scripted/CI invocations where an env var feeding the flag is unset or empty, copy-paste dropped the flag value, or quoting issues leave the argument blank.

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