{"record":{"id":"41709c3894f1cfbd","repo":"jackwener/OpenCLI","slug":"weread-official-label-is-required","errorCode":null,"errorMessage":"weread-official: ${label} is required","messagePattern":"weread-official: (.+?) is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weread-official/utils.js","lineNumber":262,"sourceCode":"\nexport function requireText(value, label) {\n    const text = String(value ?? '').trim();\n    if (!text) throw new ArgumentError(`weread-official: ${label} cannot be empty`);\n    return text;\n}\n\nexport function requireBookId(value, label = 'bookId') {\n    const text = requireText(value, label);\n    if (!/^[A-Za-z0-9_-]+$/.test(text)) {\n        throw new ArgumentError(`weread-official: ${label} contains invalid characters`, 'Pass a bookId from `weread-official search`.');\n    }\n    return text;\n}\n\nexport function requirePositiveInt(value, label, { defaultValue, max } = {}) {\n    if (value === undefined || value === null || value === '') {\n        if (defaultValue === undefined) {\n            throw new ArgumentError(`weread-official: ${label} is required`);\n        }\n        return defaultValue;\n    }\n    const text = String(value).trim();\n    if (!/^\\d+$/.test(text)) {\n        throw new ArgumentError(`weread-official: ${label} must be a positive integer`);\n    }\n    const n = Number(text);\n    if (!Number.isSafeInteger(n) || n < 1) {\n        throw new ArgumentError(`weread-official: ${label} must be a positive integer`);\n    }\n    if (max !== undefined && n > max) {\n        throw new ArgumentError(`weread-official: ${label} must be <= ${max}`);\n    }\n    return n;\n}\n\nexport function requireChoice(value, choices, label, defaultValue) {","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weread-official/utils.js#L244-L280","documentation":"requirePositiveInt validates that an option/argument is present and is a positive integer. When the value is undefined, null, or an empty string and no defaultValue was supplied, it throws this ArgumentError naming the missing parameter via ${label}. It is a fail-fast guard so commands never issue API requests with invalid paging/count arguments.","triggerScenarios":"Calling requirePositiveInt(value, label) from commands like count or listNotebooks without passing a defaultValue, while the user omitted the flag (e.g. --count not provided, or explicitly empty).","commonSituations":"Users running the CLI without the required option; scripts passing empty shell variables (FOO=\"\" cli ...); programmatic callers omitting an options object field; a changed CLI flag name in a newer version.","solutions":["Pass the required option, e.g. --count 10 / --limit 5, matching the label in the message.","If the caller should have a default, pass { defaultValue: N } to requirePositiveInt at the call site.","Check the command's --help output for the exact flag name; the flag may have been renamed.","In scripts, guard shell variables: use ${COUNT:-10} or exit early with a clear message before invoking the CLI."],"exampleFix":"// before\nrunListNotebooks({});\n// after\nrunListNotebooks({ limit: 10 }); // or requirePositiveInt(opts.limit, 'limit', { defaultValue: 20 })","handlingStrategy":"validation","validationCode":"const raw = process.env.NOTEBOOK_COUNT ?? opts.count;\nif (raw === undefined || raw === null || raw === '') {\n  throw new Error('count/limit option is required before calling this command');\n}","typeGuard":"function isProvided(v) { return v !== undefined && v !== null && v !== ''; }","tryCatchPattern":"try {\n  await cli.run(['listNotebooks', '--count', count]);\n} catch (e) {\n  if (e instanceof ArgumentError && /is required$/.test(e.message)) {\n    console.error('Missing option:', e.message); process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Always pass explicit count/limit options in scripts instead of relying on flags being set.","Give shell variables fallbacks: ${COUNT:-10}.","Pass defaultValue at call sites where an option is genuinely optional.","Check --help before scripting a new command."],"tags":["argument-validation","cli","missing-parameter"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}