{"record":{"id":"bc828abf37f627fc","repo":"jackwener/OpenCLI","slug":"oeis-label-must-be-maxvalue","errorCode":null,"errorMessage":"oeis ${label} must be <= ${maxValue}","messagePattern":"oeis (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/oeis/utils.js","lineNumber":27,"sourceCode":"\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    }\n    return stripped;\n}\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/oeis/utils.js#L9-L45","documentation":"requireBoundedInt enforces an upper bound (maxValue) on numeric options; when the parsed integer exceeds the allowed maximum it throws this ArgumentError naming the label and cap. This keeps requests to the OEIS API within sane/supported sizes. It is thrown after the positive-integer check, so the value is already a valid integer.","triggerScenarios":"Calling limit(value, ...) with an integer n where n > maxValue (e.g. limit(500, 10, 100) or `--limit 500` when the cap is 100).","commonSituations":"Users requesting a very large page size (e.g. `--limit 1000`) assuming the API supports it, or a script iterating with an oversized batch size.","solutions":["Lower the value to at most the stated max, e.g. `--limit 100`.","Read the error message: it includes the exact allowed maximum.","If you need more data, fetch multiple pages within the bound instead of one oversized request."],"exampleFix":"// before\ncli --limit 1000\n// after\ncli --limit 100","handlingStrategy":"validation","validationCode":"const n = Number(raw);\nif (Number.isInteger(n) && n > 100) throw new Error(`--limit must be <= 100, got: ${raw}`);","typeGuard":"function isWithinBound(v, max) { const n = Number(v); return Number.isInteger(n) && n > 0 && n <= max; }","tryCatchPattern":"try { const limit = requireBoundedInt(opts.limit, 10, 100); } catch (e) { console.error(e.message); process.exitCode = 1; }","preventionTips":["Clamp user input with Math.min(n, maxValue) before calling.","Paginate with multiple bounded requests instead of one oversized one.","Document the cap in your script's help text."],"tags":["validation","input","limits"],"backgroundTag":"value-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}