jackwener/OpenCLI · error · ArgumentError

Missing required argument: ${name}

Error message

Missing required argument: ${name}

What it means

requireString is the CLI's input-validation helper: it asserts that a named argument exists in the kwargs object and is a non-empty (after trim) string. If not, it throws ArgumentError with 'Missing required argument: <name>'. This is fail-fast validation so the automation never runs with incomplete reimbursement data.

Source

Thrown at clis/mercury/utils.js:11

import fs from 'node:fs';
import path from 'node:path';
import { ArgumentError, AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';

export const MERCURY_EXPENSES_URL = 'https://app.mercury.com/expenses/my-expenses';
export const RECEIPT_INPUT_SELECTOR = '[data-testid="expense-attachment-upload"]';

export function requireString(kwargs, name) {
    const value = kwargs[name];
    if (typeof value !== 'string' || value.trim() === '') {
        throw new ArgumentError(`Missing required argument: ${name}`);
    }
    return value.trim();
}

export function optionalString(kwargs, name, fallback) {
    const value = kwargs[name];
    if (typeof value !== 'string' || value.trim() === '') return fallback;
    return value.trim();
}

export function optionalBoolean(kwargs, name, fallback = false) {
    const value = kwargs[name];
    if (typeof value === 'boolean') return value;
    if (typeof value === 'string') {
        const normalized = value.trim().toLowerCase();
        if (['1', 'true', 'yes', 'y', 'on'].includes(normalized)) return true;
        if (['0', 'false', 'no', 'n', 'off'].includes(normalized)) return false;
        throw new ArgumentError(`Boolean argument ${name} must be true or false`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the missing argument explicitly, e.g. --receipt /path/to/receipt.pdf with a non-empty string value.
  2. Check quoting in the shell/CI so the value is not swallowed (empty string still fails validation).
  3. Inspect the calling code (normalizeReimbursementInput) to confirm which argument name is required and its expected format.
  4. If a numeric argument (like amount) is intended, pass it as a string per the CLI's expected input format.

Example fix

// before
await draftReimbursement({});
// after
await draftReimbursement({ receipt: '/invoices/receipt.pdf', amount: '42.50', date: '2026-08-29', merchant: 'Acme' });
Defensive patterns

Strategy: validation

Validate before calling

function assertRequiredArgs(kwargs, names) {
    for (const n of names) {
        if (typeof kwargs[n] !== 'string' || kwargs[n].trim() === '') {
            throw new Error(`Missing required argument: ${n}`);
        }
    }
}
assertRequiredArgs(input, ['receipt', 'amount', 'date']);

Type guard

function hasString(v) { return typeof v === 'string' && v.trim() !== ''; }
const inputValid = (i) => hasString(i.receipt) && hasString(i.amount) && hasString(i.date);

Try / catch

try {
    await draftReimbursement(input);
} catch (err) {
    if (err instanceof ArgumentError && err.message.startsWith('Missing required argument')) {
        console.error('Usage: provide --receipt <path> --amount <n> --date <YYYY-MM-DD>');
        process.exitCode = 2;
        return;
    }
    throw err;
}

Prevention

When it happens

Trigger: Calling normalizeReimbursementInput (or the receipt/amount/date helpers) with kwargs lacking the given key, or with a value that is not a string or is whitespace-only — e.g. omitting --receipt, passing an empty string, or passing a non-string type (number/null).

Common situations: CLI invocation missing a required flag; a wrapper script passes empty env vars; JSON config has the key with null or a number instead of a string; shell quoting strips the value so only an empty string arrives.

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