{"record":{"id":"a9351bf4700a9672","repo":"jackwener/OpenCLI","slug":"wikidata-entity-id-is-required-e-g-q937","errorCode":null,"errorMessage":"wikidata entity id is required (e.g. \"Q937\")","messagePattern":"wikidata entity id is required \\(e\\.g\\. \"Q937\"\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/wikidata/utils.js","lineNumber":37,"sourceCode":"    if (!s) throw new ArgumentError(`wikidata ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`wikidata ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`wikidata ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireEntityId(value) {\n    const raw = String(value ?? '').trim().toUpperCase();\n    if (!raw) throw new ArgumentError('wikidata entity id is required (e.g. \"Q937\")');\n    // Tolerate URL-paste like `https://www.wikidata.org/wiki/Q937`.\n    const stripped = raw.replace(/^HTTPS?:\\/\\/[^/]+\\/WIKI\\//i, '');\n    if (!ENTITY_ID_PATTERN.test(stripped)) {\n        throw new ArgumentError(\n            `wikidata entity id \"${value}\" is not a valid Q/P/L identifier`,\n            'Expected format: \"Q<digits>\" (item), \"P<digits>\" (property), or \"L<digits>\" (lexeme).',\n        );\n    }\n    return stripped;\n}\n\nexport function requireLanguage(value, defaultValue = 'en') {\n    const raw = String(value ?? defaultValue).trim().toLowerCase();\n    // Wikidata language codes are 2-3 letter ISO 639 codes plus optional region (`zh-hans`).\n    if (!/^[a-z]{2,3}(-[a-z]{2,8})?$/.test(raw)) {\n        throw new ArgumentError(\n            `wikidata language \"${value}\" is not a valid language code`,\n            'Expected an ISO 639 language code such as \"en\", \"fr\", \"zh\", \"zh-hans\".',","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wikidata/utils.js#L19-L55","documentation":"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.","triggerScenarios":"Calling `wikidata entity` with a missing, empty, or whitespace-only id argument — e.g. `wikidata entity ''` or a variable that resolved to nothing.","commonSituations":"Forgetting the positional argument on the command line; an upstream pipeline passing an undefined/empty qid; a shell variable that was never set.","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"],"exampleFix":"// before\nconst qid = args[0]; // may be undefined\nawait runCli(['wikidata', 'entity', qid]);\n// after\nif (!args[0]) throw new Error('usage: wikidata entity <QID>');\nawait runCli(['wikidata', 'entity', args[0]]);","handlingStrategy":"validation","validationCode":"const qid = args[0];\nif (qid == null || String(qid).trim() === '') throw new Error('wikidata entity requires an id like Q937');","typeGuard":"function hasEntityId(args) { return Array.isArray(args) && typeof args[0] === 'string' && args[0].trim().length > 0; }","tryCatchPattern":"try {\n    await runCli(['wikidata', 'entity', qid]);\n} catch (e) {\n    if (/entity id is required/.test(e.message)) {\n        console.error('usage: wikidata entity <QID>  e.g. wikidata entity Q937');\n        process.exitCode = 2;\n    } else throw e;\n}","preventionTips":["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"],"tags":["validation","arguments","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}