jackwener/OpenCLI · error · ArgumentError
wikidata entity id is required (e.g. "Q937")
Error message
wikidata entity id is required (e.g. "Q937")
What it means
requireEntityId validates the entity ID argument for `wikidata entity`. If the value is empty after trimming, it throws this ArgumentError with an example of the expected format. It exists to fail fast before any network request is made.
Solutions
- Supply an entity ID, e.g. `wikidata entity Q937`
- Check the variable/config feeding the argument is non-empty
- Run `wikidata search <term>` first to obtain a valid QID
Example fix
// before
const qid = args[0]; // may be undefined
await runCli(['wikidata', 'entity', qid]);
// after
if (!args[0]) throw new Error('usage: wikidata entity <QID>');
await runCli(['wikidata', 'entity', args[0]]); Defensive patterns
Strategy: validation
Validate before calling
const qid = args[0];
if (qid == null || String(qid).trim() === '') throw new Error('wikidata entity requires an id like Q937'); Type guard
function hasEntityId(args) { return Array.isArray(args) && typeof args[0] === 'string' && args[0].trim().length > 0; } Try / catch
try {
await runCli(['wikidata', 'entity', qid]);
} catch (e) {
if (/entity id is required/.test(e.message)) {
console.error('usage: wikidata entity <QID> e.g. wikidata entity Q937');
process.exitCode = 2;
} else throw e;
} Prevention
- Check positional args exist before spawning the CLI
- Give shell variables defaults: ${QID:?missing QID}
- Search first to obtain a QID rather than assuming one
- Validate argv length in wrapper scripts
When it happens
Trigger: Calling `wikidata entity` with a missing, empty, or whitespace-only id argument — e.g. `wikidata entity ''` or a variable that resolved to nothing.
Common situations: Forgetting the positional argument on the command line; an upstream pipeline passing an undefined/empty qid; a shell variable that was never set.
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
- account must be an integer between 0 and 20
- --adults must be an integer between 1 and 9, got
- ARGUMENT
- ARGUMENT
- ARGUMENT
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a9351bf4700a9672.
Report an issue: GitHub.
Appendix: source
Thrown at clis/wikidata/utils.js:37
if (!s) throw new ArgumentError(`wikidata ${label} cannot be empty`);
return s;
}
export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
const raw = value ?? defaultValue;
const n = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isInteger(n) || n <= 0) {
throw new ArgumentError(`wikidata ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`wikidata ${label} must be <= ${maxValue}`);
}
return n;
}
export function requireEntityId(value) {
const raw = String(value ?? '').trim().toUpperCase();
if (!raw) throw new ArgumentError('wikidata entity id is required (e.g. "Q937")');
// Tolerate URL-paste like `https://www.wikidata.org/wiki/Q937`.
const stripped = raw.replace(/^HTTPS?:\/\/[^/]+\/WIKI\//i, '');
if (!ENTITY_ID_PATTERN.test(stripped)) {
throw new ArgumentError(
`wikidata entity id "${value}" is not a valid Q/P/L identifier`,
'Expected format: "Q<digits>" (item), "P<digits>" (property), or "L<digits>" (lexeme).',
);
}
return stripped;
}
export function requireLanguage(value, defaultValue = 'en') {
const raw = String(value ?? defaultValue).trim().toLowerCase();
// Wikidata language codes are 2-3 letter ISO 639 codes plus optional region (`zh-hans`).
if (!/^[a-z]{2,3}(-[a-z]{2,8})?$/.test(raw)) {
throw new ArgumentError(
`wikidata language "${value}" is not a valid language code`,
'Expected an ISO 639 language code such as "en", "fr", "zh", "zh-hans".',View on GitHub (pinned to 49907e53dc)