jackwener/OpenCLI · error · ArgumentError
rfc number "${value}" is not a valid RFC number
Error message
rfc number "${value}" is not a valid RFC number What it means
requireRfcNumber rejects values that are not positive integers after stripping an optional 'rfc' prefix. The canonical-string check (String(n) !== s) also rejects leading zeros, plus signs, and decimals, throwing ArgumentError with the offending raw value.
Source
Thrown at clis/rfc/utils.js:23
// (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;
}
export async function rfcFetch(url, label) {
let resp;
try {
resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
}
catch (err) {
throw new CommandExecutionError(
`${label} request failed: ${err?.message ?? err}`,View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a plain positive integer without leading zeros, e.g. --number 9000.
- Remove leading zeros ('007' → 7).
- Strip units, commas, or surrounding text from the value.
- Validate with /^\d+$/ before invoking if calling programmatically.
Example fix
// before rfc rfc --number 007 // after rfc rfc --number 7
Defensive patterns
Strategy: validation
Validate before calling
function isValidRfcNumber(v) {
if (v == null) return false;
const s = String(v).trim().toLowerCase().replace(/^rfc/, '');
return /^\d+$/.test(s) && Number(s) > 0 && String(Number(s)) === s;
}
if (!isValidRfcNumber(input)) input = String(Number(String(input).replace(/^rfc/i, ''))); Type guard
const isRfcNumber = (v) => typeof v === 'string' && /^\d+$/.test(v.trim().toLowerCase().replace(/^rfc/, ''));
Try / catch
try {
const n = requireRfcNumber(input);
} catch (err) {
if (err instanceof ArgumentError) {
console.error(`Bad RFC number: ${err.message}`);
} else throw err;
} Prevention
- Strip leading zeros before passing values ('007' → 7).
- Sanitize pasted input: remove text, commas, and whitespace.
- Use a regex ^\d+$ pre-check in scripts.
- Store RFC numbers as plain integers, not formatted strings.
When it happens
Trigger: Passing --number 'abc', --number '0', --number '-5', --number '007', --number '90.5', or any non-integer string to the rfc CLI.
Common situations: Users including stray text ('rfc 9000 draft'), zero-padded numbers copied from URLs ('rfc0261'), negative numbers from bad arithmetic, or locale-formatted numbers ('9,000').
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/7cb922695f9503a1.
Report an issue: GitHub.