{"record":{"id":"3f2041cf4708dc35","repo":"jackwener/OpenCLI","slug":"oeis-label-must-be-a-positive-integer","errorCode":null,"errorMessage":"oeis ${label} must be a positive integer","messagePattern":"oeis (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/oeis/utils.js","lineNumber":24,"sourceCode":"\nexport const OEIS_BASE = 'https://oeis.org';\nconst UA = 'opencli-oeis-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';\n\n// OEIS ids are A followed by 6 zero-padded digits (older entries use 6 by convention,\n// modern entries can be longer; OEIS itself accepts any digits after A).\nconst SEQUENCE_ID_PATTERN = /^A\\d{1,7}$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`oeis ${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(`oeis ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`oeis ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireSequenceId(value) {\n    const raw = String(value ?? '').trim().toUpperCase();\n    if (!raw) throw new ArgumentError('oeis sequence id is required (e.g. \"A000045\" for Fibonacci)');\n    // Tolerate common URL paste like `https://oeis.org/A000045`.\n    const stripped = raw.replace(/^HTTPS?:\\/\\/(?:WWW\\.)?OEIS\\.ORG\\//, '').replace(/\\/.*$/, '');\n    if (!SEQUENCE_ID_PATTERN.test(stripped)) {\n        throw new ArgumentError(\n            `oeis sequence id \"${value}\" is not a valid A-number`,\n            'Expected format: \"A\" + digits (e.g. \"A000045\").',\n        );\n    }","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/oeis/utils.js#L6-L42","documentation":"requireBoundedInt normalizes a numeric CLI option (defaulting when undefined) and throws this ArgumentError when the value is not an integer greater than zero. The OEIS CLI uses it to validate options like `limit`, so callers never pass invalid paging/sizing values downstream. It fires before any network call, purely as input validation.","triggerScenarios":"Calling limit(value, ...) with a non-integer number (e.g. 2.5), a zero or negative number, or a string that Number() cannot coerce to a positive integer (e.g. limit('abc') or limit('')).","commonSituations":"Typing `--limit 0` or `--limit -5` on the CLI, pasting a float like `--limit 10.5`, or passing an empty string from a shell variable that was never set.","solutions":["Pass a positive whole number, e.g. `--limit 10`.","Omit the option to use the built-in default value.","If computing the value in a script, round with Math.floor() and clamp to >= 1 before calling."],"exampleFix":"// before\ncli --limit 0\n// after\ncli --limit 10","handlingStrategy":"validation","validationCode":"const n = Number(raw);\nif (!Number.isInteger(n) || n <= 0) throw new Error(`--limit must be a positive integer, got: ${raw}`);","typeGuard":"function isPositiveInt(v) { const n = typeof v === 'number' ? v : Number(v); return Number.isInteger(n) && n > 0; }","tryCatchPattern":"try { const limit = requireBoundedInt(opts.limit, 10, 100); } catch (e) { console.error(e.message); process.exitCode = 1; }","preventionTips":["Validate numeric CLI flags at argument-parse time, before any I/O.","Prefer omitting the flag to rely on the library default.","Round/clamp computed values before passing them in."],"tags":["validation","input","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}