jackwener/OpenCLI · error · ArgumentError
${label} must be a numeric ID
Error message
${label} must be a numeric ID What it means
normalizeNumericId validates that a value (issue/page ID) is a string of digits only. Anything else — alphanumeric keys, undefined, objects, negative numbers, floats — throws ArgumentError '<label> must be a numeric ID' with a usage hint including an example.
Source
Thrown at clis/_shared/common.js:22
import { ArgumentError } from '@jackwener/opencli/errors';
/**
* Clamp a numeric value to [min, max].
* Matches the signature of lodash.clamp and Rust's clamp.
*/
export function clamp(value, min, max) {
return Math.max(min, Math.min(value, max));
}
export function clampInt(raw, fallback, min, max) {
const parsed = Number(raw);
if (!Number.isFinite(parsed)) {
return fallback;
}
return clamp(Math.floor(parsed), min, max);
}
export function normalizeNumericId(value, label, example) {
const normalized = String(value ?? '').trim();
if (!/^\d+$/.test(normalized)) {
throw new ArgumentError(`${label} must be a numeric ID`, `Pass a numeric ${label}, for example: ${example}`);
}
return normalized;
}
export function requireNonEmptyQuery(value, label = 'query') {
const normalized = String(value ?? '').trim();
if (!normalized) {
throw new ArgumentError(`${label} cannot be empty`);
}
return normalized;
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Look up the numeric ID (e.g. via the corresponding get/search command) and pass digits only, e.g. 10001 not PROJ-123.
- Trim and sanitize the value before calling; ensure it matches /^\d+$/.
- Fix the upstream code path returning null/undefined so a real ID reaches the call.
Example fix
// before
normalizeNumericId('PROJ-123', 'issue ID', '12345')
// after
normalizeNumericId('12345', 'issue ID', '12345') Defensive patterns
Strategy: validation
Validate before calling
const id = String(value ?? '').trim();
if (!/^\d+$/.test(id)) throw new Error(`${label} must be numeric digits, got: ${value}`); Type guard
const isNumericId = (v) => typeof v !== 'object' && /^\d+$/.test(String(v ?? '').trim());
Try / catch
try {
const id = normalizeNumericId(input, 'issue ID', '12345');
} catch (err) {
if (err.name === 'ArgumentError' && err.message.includes('numeric ID')) {
console.error('Pass the numeric ID (e.g. 12345), not the issue key (e.g. PROJ-123).');
}
throw err;
} Prevention
- Resolve issue keys (PROJ-123) to numeric IDs via the API before write operations.
- Validate IDs with /^\d+$/ at config-load time.
- Fail fast when an upstream lookup returns null/undefined instead of passing it downstream.
When it happens
Trigger: Calling normalizeNumericId (or a CLI flag routed through it) with a human-readable key like 'PROJ-123', 'ABC123', an empty string, undefined, a negative or decimal number, or an object.
Common situations: Passing an issue KEY (PROJ-123) where a numeric issue ID is required; pasting an ID with whitespace plus stray characters; passing null/undefined because an earlier lookup failed; passing a float like 12345.0 from JSON config.
Related errors
- ${label} cannot be empty
- ${label} must be an integer between ${min} and ${max}, got $
- ${label} must be between ${min} and ${max}, got ${parsed}
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5376b0fe5665f2a7.
Report an issue: GitHub.