jackwener/OpenCLI · error · ArgumentError

${label} is required

Error message

${label} is required

What it means

requireString throws this ArgumentError when a required string argument is missing, empty, or whitespace-only after String() coercion and trimming. It is the input-validation gate for mandatory CLI parameters (page IDs, titles, space keys, issue keys, etc.).

Source

Thrown at clis/_atlassian/shared.js:242

}

export function queryString(params) {
    const qs = new URLSearchParams();
    for (const [key, value] of Object.entries(params)) {
        if (value === undefined || value === null || value === '') continue;
        if (Array.isArray(value)) {
            for (const item of value) qs.append(key, String(item));
        } else {
            qs.set(key, String(value));
        }
    }
    const s = qs.toString();
    return s ? `?${s}` : '';
}

export function requireString(value, label) {
    const s = String(value ?? '').trim();
    if (!s) throw new ArgumentError(`${label} is required`);
    return s;
}

export function requirePayloadObject(value, label) {
    if (!value || typeof value !== 'object' || Array.isArray(value)) {
        throw new CommandExecutionError(`${label} returned an unexpected payload shape; expected an object.`);
    }
    return value;
}

export function requirePayloadArray(value, label) {
    if (!Array.isArray(value)) {
        throw new CommandExecutionError(`${label} returned an unexpected payload shape; expected an array.`);
    }
    return value;
}

export function requirePayloadString(value, field, label) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Supply the missing argument named by ${label} (e.g. --id, --title, --space).
  2. If the value comes from a shell variable, verify it is non-empty before invoking (echo it or use ${VAR:?}).
  3. Check the command's help output for which arguments are mandatory.
  4. In scripts, fail fast when upstream commands produce empty output instead of forwarding it.

Example fix

# before
opencli confluence get page --id "$PAGE_ID"   # PAGE_ID empty
# after
: "${PAGE_ID:?PAGE_ID must be set}"
opencli confluence get page --id "$PAGE_ID"
Defensive patterns

Strategy: validation

Validate before calling

function requireArg(v, label) {
  const s = String(v ?? '').trim();
  if (!s) throw new Error(`${label} is required`);
  return s;
}
const id = requireArg(args.id, 'page id');

Type guard

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

Try / catch

try {
  const page = await cmd({ id: args.id });
} catch (e) {
  if (e instanceof ArgumentError || /is required/.test(e.message)) {
    console.error(`Usage: ${cmdName} --id <pageId>`);
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling a command without its required positional/flag argument, e.g. confluence get page with no --id, or passing --title "" / whitespace; also null/undefined values passed programmatically.

Common situations: Forgot a required flag in a script; shell variable holding the ID is empty because an earlier command failed; YAML/JSON pipeline passes null for an optional-looking field that is actually required.

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