{"record":{"id":"cdc21d80c9798d65","repo":"jackwener/OpenCLI","slug":"label-must-be-an-integer-min-got-json","errorCode":null,"errorMessage":"${label} must be an integer >= ${min}, got ${JSON.stringify(value)}","messagePattern":"(.+?) must be an integer >= (.+?), got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/stackoverflow/read.js","lineNumber":82,"sourceCode":"    }\n    return json;\n}\n\n/**\n * CLI args may arrive as strings (`--limit 5` → `'5'`) when not coerced by the\n * arg type system. Coerce-then-validate so `Number.isInteger` actually catches\n * the bad cases, and reject NaN explicitly.\n */\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);","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/stackoverflow/read.js#L64-L100","documentation":"requireMinInt throws this ArgumentError when a CLI option expected to be an integer of at least `min` is missing, non-numeric, non-integer, or below the minimum. The offending raw value is included via JSON.stringify. It exists so bad user input fails fast with a clear message instead of producing a nonsense API request.","triggerScenarios":"Running `stackoverflow read` with --max-length below 100, a non-integer like 12.5, a non-numeric string like 'abc', or empty/undefined so coerceInt yields NaN.","commonSituations":"Typo in the flag value (e.g. --max-length 50); shell passing an empty string for an unset flag; scripts interpolating an unset variable so the value arrives as '' or 'NaN'; copy-pasting a float like 1000.5.","solutions":["Pass an integer >= 100 for --max-length, e.g. --max-length 4000","Check the script/shell for unset variables yielding empty or 'NaN' values","Quote or validate the value in wrapper scripts before invoking the CLI"],"exampleFix":"// before\nstackoverflow read 79935770 --max-length 50\n// after\nstackoverflow read 79935770 --max-length 4000","handlingStrategy":"validation","validationCode":"const n = Number(value);\nif (!Number.isInteger(n) || n < 100) throw new Error(`max-length must be an integer >= 100, got ${value}`);","typeGuard":"function isIntAtLeast(value, min) {\n  return typeof value === 'number' || typeof value === 'string'\n    ? Number.isInteger(Number(value)) && Number(value) >= min\n    : false;\n}","tryCatchPattern":"try {\n  await runCommand(['stackoverflow', 'read', id, '--max-length', String(len)]);\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('must be an integer >= 100')) {\n    console.error('Fix --max-length: pass an integer >= 100');\n  } else throw e;\n}","preventionTips":["Always pass explicit numeric values, not shell variables that may be unset","Clamp/parse values in wrapper scripts before invoking the CLI","Remember the floor is 100 for --max-length","Use `${var:-4000}` style defaults in shell wrappers"],"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"}