{"record":{"id":"f4874305943c283c","repo":"jackwener/OpenCLI","slug":"medium-limit-must-be-a-positive-integer","errorCode":null,"errorMessage":"medium limit must be a positive integer","messagePattern":"medium limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/medium/tag.js","lineNumber":69,"sourceCode":"function requireTag(value) {\n    const s = String(value ?? '').trim().toLowerCase();\n    if (!s) {\n        throw new ArgumentError('medium tag is required (e.g. \"programming\", \"javascript\")');\n    }\n    if (!TAG_PATTERN.test(s)) {\n        throw new ArgumentError(\n            `medium tag \"${value}\" is not valid`,\n            'Tags are lowercase alphanumeric, optionally hyphenated (e.g. \"machine-learning\").',\n        );\n    }\n    return s;\n}\n\nfunction requireBoundedInt(value, defaultValue, maxValue) {\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('medium limit must be a positive integer');\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`medium limit must be <= ${maxValue}`);\n    }\n    return n;\n}\n\ncli({\n    site: 'medium',\n    name: 'tag',\n    access: 'read',\n    description: 'Latest Medium articles tagged with a given keyword (RSS feed)',\n    domain: 'medium.com',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'tag', positional: true, required: true, help: 'Lowercase tag slug (e.g. \"programming\", \"machine-learning\")' },\n        { name: 'limit', type: 'int', default: 20, help: 'Max articles (1-25 — single RSS page)' },","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/medium/tag.js#L51-L87","documentation":"The medium tag command's --limit option is normalized by requireBoundedInt, which coerces the raw value to a number and requires it to be a positive integer before checking the upper bound. ArgumentError is thrown when the value is not an integer or is <= 0 (non-numeric strings, decimals, zero, negatives, NaN).","triggerScenarios":"Running `medium tag <tag> --limit 0`, a negative value like `--limit -3`, a decimal like `--limit 2.5`, or a non-numeric string like `--limit all` or `--limit 10x`.","commonSituations":"Passing 'all' or 'max' expecting a sentinel; typo'd flag values; locale-formatted numbers ('1,000'); forgetting the flag belongs to another command so a word lands in limit; programmatically passing undefined is fine (falls back to defaultValue) but null-coalesced empty strings fail.","solutions":["Pass a positive whole number, e.g. `medium tag programming --limit 10`.","Omit --limit entirely to use the default value handled by requireBoundedInt.","If building the value in a script, coerce with Math.floor(Number(value)) and validate Number.isInteger(n) && n > 0 before calling.","Check the command's maxValue from the cli() definition to also stay within the upper bound."],"exampleFix":"// before\nmedium tag programming --limit all\n// after\nmedium tag programming --limit 10","handlingStrategy":"validation","validationCode":"const n = Number(limit);\nif (!Number.isInteger(n) || n <= 0) throw new Error('--limit must be a positive integer');","typeGuard":"function isPositiveInt(v) {\n  return typeof v === 'number' && Number.isInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  await run(['medium', 'tag', tag, '--limit', String(limit)]);\n} catch (e) {\n  if (e instanceof ArgumentError && /limit must be a positive integer/.test(e.message)) {\n    console.error('Use a whole number > 0, e.g. --limit 10');\n  } else throw e;\n}","preventionTips":["Always pass limits as stringified integers when shelling out.","Avoid sentinel words like 'all'/'max' — use the default by omitting the flag.","Coerce and validate with Number.isInteger before invoking the CLI.","Document limit semantics in scripts that wrap the command."],"tags":["cli","validation","argument-error","numeric-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}