jackwener/OpenCLI · error · ArgumentError

${label} is required

Error message

${label} is required

What it means

requireStringArg normalizes an argument (collapsing whitespace/nbsp and trimming) and throws ArgumentError if nothing remains. It guarantees that required string CLI arguments are non-empty before any work is done.

Source

Thrown at clis/linkedin/salesnav-message.js:17

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { unwrapEvaluateResult } from './shared.js';

const LINKEDIN_DOMAIN = 'www.linkedin.com';
const SALES_HOME = 'https://www.linkedin.com/sales/';
const PROFILE_DECO = '(entityUrn,objectUrn,firstName,lastName,fullName,headline,degree,inmailRestriction,memberBadges,defaultPosition)';
const CREDITS_URL = 'https://www.linkedin.com/sales-api/salesApiCredits?q=findCreditGrant&creditGrantType=LSS_INMAIL';
const MESSAGE_ACTION_URL = 'https://www.linkedin.com/sales-api/salesApiMessageActions?action=createMessage';

function normalizeWhitespace(value) {
  return String(value ?? '').replace(/[\u00a0\u202f]/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 isLinkedInHost(hostname) {
  const host = String(hostname || '').toLowerCase();
  return host === 'linkedin.com' || host.endsWith('.linkedin.com');
}

function parseSalesProfileUrn(value) {
  const raw = normalizeWhitespace(value);
  const match = raw.match(/^urn:li:fs_salesProfile:\(([^,()]+),([^,()]+),([^,()]+)\)$/);
  if (!match) return null;
  if (!isResolvedSalesProfileParts(match[1], match[2], match[3])) return null;
  return { profileId: match[1], authType: match[2], authToken: match[3], entityUrn: raw };
}

function isResolvedSalesProfileParts(profileId, authType, authToken) {
  return [profileId, authType, authToken].every((part) => {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Supply the missing argument explicitly, e.g. --recipient "urn:li:fs_salesProfile:(...)" --subject "Hello".
  2. Check shell quoting so the value is not swallowed or split by the shell.
  3. Strip stray whitespace/nbsp from the value before passing it.

Example fix

// before
linkedin salesnav-message --body "hi"
// after
linkedin salesnav-message --recipient "urn:li:fs_salesProfile:(urn:li:person:ABC,123)" --subject "Hi" --body "hi"
Defensive patterns

Strategy: validation

Validate before calling

function isFilled(v) { return String(v ?? '').replace(/[\u00a0\u202f]/g, ' ').replace(/\s+/g, ' ').trim().length > 0; }
if (!isFilled(args.recipient)) throw new Error('pass a non-empty --recipient');
if (!isFilled(args.subject)) throw new Error('pass a non-empty --subject');

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling code (e.g. recipientArg, subject) reads args[key] and the value is undefined, empty string, or only whitespace/non-breaking spaces after normalization.

Common situations: Forgetting --recipient or --subject on the salesnav-message command line; passing quoted empty strings; a value consisting solely of spaces or non-breaking-space characters pasted from rich text.

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