jackwener/OpenCLI · error · ArgumentError

rfc number is required (e.g. 9000, 791, 2616)

Error message

rfc number is required (e.g. 9000, 791, 2616)

What it means

requireRfcNumber validates that an RFC number argument was actually provided. It throws ArgumentError when the value is null/undefined or an empty/whitespace-only string, with a hint that the 'rfc' prefix should not be included.

Source

Thrown at clis/rfc/utils.js:14

// Shared helpers for the IETF RFC adapter.
//
// datatracker.ietf.org publishes a free, unauthenticated REST API. The
// `/doc/<name>/doc.json` endpoint returns rich metadata for any IETF document
// (RFCs, internet drafts, etc.). Docs: https://datatracker.ietf.org/api/
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';

export const RFC_BASE = 'https://datatracker.ietf.org';
const UA = 'opencli-rfc-adapter (+https://github.com/jackwener/opencli)';

export function requireRfcNumber(value) {
    const raw = value;
    if (raw == null || String(raw).trim() === '') {
        throw new ArgumentError(
            'rfc number is required (e.g. 9000, 791, 2616)',
            'Pass the integer RFC number; do not include the "rfc" prefix.',
        );
    }
    // Accept "9000" or 9000 or "rfc9000" as a courtesy.
    const s = String(raw).trim().toLowerCase().replace(/^rfc/, '');
    const n = Number.parseInt(s, 10);
    if (!Number.isInteger(n) || n <= 0 || String(n) !== s) {
        throw new ArgumentError(
            `rfc number "${value}" is not a valid RFC number`,
            'Pass a positive integer (e.g. 9000, 791, 2616).',
        );
    }
    if (n > 999999) {
        throw new ArgumentError('rfc number must be <= 999999');
    }
    return n;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide the RFC number, e.g. --number 9000.
  2. Ensure the shell variable holding the number is actually set and non-empty.
  3. Pass the bare integer; the 'rfc' prefix is optional but a value is required.
  4. Wrap the call in try/catch on ArgumentError to prompt the user for input.

Example fix

// before
rfc rfc --number ""
// after
rfc rfc --number 2616
Defensive patterns

Strategy: validation

Validate before calling

function hasRfcNumber(v) {
  return v != null && String(v).trim() !== '';
}
if (!hasRfcNumber(args.number)) throw new Error('usage: rfc rfc --number <int>');

Type guard

const isPresent = (v) => v !== undefined && v !== null && String(v).trim() !== '';

Try / catch

try {
  const n = requireRfcNumber(args.number);
} catch (err) {
  if (err instanceof ArgumentError) {
    console.error(err.message + '\n' + (err.hint ?? ''));
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Running `rfc rfc` without --number or with an empty value (--number '', --number ' '), or calling requireRfcNumber(null/undefined) programmatically.

Common situations: Forgetting the required argument in scripts, a variable that failed to interpolate leaving --number '' empty, or users typing 'rfc rfc rfc9000' expecting prefix parsing (prefix is accepted later, but emptiness is not).

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