{"record":{"id":"c5acbb8336e8df8c","repo":"jackwener/OpenCLI","slug":"label-must-be-an-integer-between-min-and-m-c5acbb","errorCode":null,"errorMessage":"${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(value)}","messagePattern":"(.+?) must be an integer between (.+?) and (.+?), got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/stackoverflow/read.js","lineNumber":90,"sourceCode":" */\nfunction coerceInt(value) {\n    if (value === undefined || value === null || value === '') return NaN;\n    const n = typeof value === 'number' ? value : Number(value);\n    return Number.isFinite(n) && Number.isInteger(n) ? n : NaN;\n}\n\nfunction requireMinInt(value, min, label) {\n    const n = coerceInt(value);\n    if (!Number.isInteger(n) || n < min) {\n        throw new ArgumentError(`${label} must be an integer >= ${min}, got ${JSON.stringify(value)}`);\n    }\n    return n;\n}\n\nfunction requireBoundedInt(value, min, max, label) {\n    const n = coerceInt(value);\n    if (!Number.isInteger(n) || n < min || n > max) {\n        throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(value)}`);\n    }\n    return n;\n}\n\nfunction byAcceptedThenScoreDesc(question, answers) {\n    const acceptedAnswerId = question.accepted_answer_id;\n    return answers\n        .slice()\n        .sort((a, b) => {\n            const aAccepted = a.is_accepted || (acceptedAnswerId && a.answer_id === acceptedAnswerId);\n            const bAccepted = b.is_accepted || (acceptedAnswerId && b.answer_id === acceptedAnswerId);\n            if (aAccepted !== bAccepted) return aAccepted ? -1 : 1;\n            return (b.score ?? 0) - (a.score ?? 0);\n        });\n}\n\nasync function fetchMissingAcceptedAnswer(question, answers, label) {\n    const acceptedAnswerId = question.accepted_answer_id;","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/stackoverflow/read.js#L72-L108","documentation":"requireBoundedInt throws this ArgumentError when a CLI option must be an integer within [min, max] but the value is missing, non-numeric, non-integer, or out of range. Here it guards --answers-limit and --comments-limit against the Stack Exchange max page size (100). Values are string-coerced first so '--limit 5' arriving as '5' still validates.","triggerScenarios":"`stackoverflow read` invoked with --answers-limit or --comments-limit set to 0, negative, above 100, a float like 2.5, or a non-numeric string; value also fails when unset/empty (NaN).","commonSituations":"Trying to fetch more answers than the API page size allows (e.g. --answers-limit 500); shell passing empty string for an omitted flag; scripts building the command with an unset variable; typo like --comments-limit five.","solutions":["Set the flag to an integer between 1 and 100 (SE_MAX_PAGE_SIZE), e.g. --answers-limit 10","If more than 100 answers are needed, rely on the CLI's paging limits or paginate manually via the API","Sanitize the value in wrapper scripts (parseInt and clamp) before invoking"],"exampleFix":"// before\nstackoverflow read 79935770 --answers-limit 500\n// after\nstackoverflow read 79935770 --answers-limit 100","handlingStrategy":"validation","validationCode":"const n = Number(value);\nif (!Number.isInteger(n) || n < 1 || n > 100) throw new Error(`limit must be an integer between 1 and 100, got ${value}`);","typeGuard":"function isBoundedInt(value, min, max) {\n  const n = Number(value);\n  return Number.isInteger(n) && n >= min && n <= max;\n}","tryCatchPattern":"try {\n  await runCommand(['stackoverflow', 'read', id, '--answers-limit', String(limit)]);\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('must be an integer between')) {\n    console.error('Use an integer between 1 and 100 for --answers-limit/--comments-limit');\n  } else throw e;\n}","preventionTips":["Cap limits at 100 (SE_MAX_PAGE_SIZE) — the API page size maximum","Default to 10 answers / 5 comments when in doubt","Guard against unset shell variables producing empty strings","Use Math.min(100, Math.max(1, n)) to clamp before invoking"],"tags":["validation","argument-error","cli-input"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}