{"record":{"id":"6b963e54c3798e5b","repo":"jackwener/OpenCLI","slug":"label-must-be-a-positive-integer-6b963e","errorCode":null,"errorMessage":"${label} must be a positive integer","messagePattern":"(.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/lobsters/read.js","lineNumber":33,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nconst LOBSTERS_STORY_BASE = 'https://lobste.rs/s';\n\nasync function fetchStory(shortId) {\n    const res = await fetch(`${LOBSTERS_STORY_BASE}/${shortId}.json`);\n    if (res.status === 404) {\n        throw new EmptyResultError(`lobsters/${shortId}`, 'Story not found');\n    }\n    if (!res.ok) {\n        throw new CommandExecutionError(`Lobsters API HTTP ${res.status} for story ${shortId}`, 'Check the short id');\n    }\n    return res.json();\n}\n\nfunction requirePositiveInt(value, label) {\n    if (!Number.isInteger(value) || value <= 0) {\n        throw new ArgumentError(`${label} must be a positive integer`);\n    }\n    return value;\n}\n\nfunction requireMinInt(value, min, label) {\n    if (!Number.isInteger(value) || value < min) {\n        throw new ArgumentError(`${label} must be an integer >= ${min}`);\n    }\n    return value;\n}\n\n/** Lobsters returns comment text as a small HTML subset — convert to plain text. */\nfunction htmlToText(html) {\n    if (!html) return '';\n    return String(html)\n        .replace(/<p>/gi, '\\n\\n')\n        .replace(/<\\/p>/gi, '')\n        .replace(/<br\\s*\\/?>/gi, '\\n')","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/lobsters/read.js#L15-L51","documentation":"Thrown by requirePositiveInt in clis/lobsters/read.js:33 when a numeric CLI argument that must be >= 1 is not a positive integer. Used for --limit (top-level comments), --depth (max reply depth), and --replies (max replies per level). ArgumentError indicates caller input error, not a network problem.","triggerScenarios":"Passing `--limit 0`, `--depth -1`, `--replies abc`, or a non-integer like `--limit 2.5` (or a value parsed as non-int). Any of limit/depth/replies failing Number.isInteger or being <= 0 raises it.","commonSituations":"Typing negative numbers intending 'no limit'; copying float values from scripts; passing string flags in wrapper scripts where type coercion doesn't happen; forgetting defaults when args come from a JSON pipeline with null/0 values.","solutions":["Pass a positive whole number, e.g. `lobsters read 6cmh6h --limit 25 --depth 2 --replies 5`","Check wrapper scripts aren't passing 0/null for these flags; omit the flag to use defaults (25/2/5)","Coerce strings to integers with Number.parseInt before invoking if calling programmatically","Use --depth 1 if you want no replies — 1, not 0"],"exampleFix":"// before\nlobsters read 6cmh6h --depth 0\n// after\nlobsters read 6cmh6h --depth 1","handlingStrategy":"validation","validationCode":"function assertPositiveInt(v, label) {\n  if (!Number.isInteger(v) || v <= 0) throw new Error(`${label} must be a positive integer`);\n}\nassertPositiveInt(limit, 'limit');\nassertPositiveInt(depth, 'depth');\nassertPositiveInt(replies, 'replies');","typeGuard":"function isPositiveInt(v) {\n  return Number.isInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  await run(['lobsters', 'read', id, '--limit', String(limit)]);\n} catch (e) {\n  if (e.message.includes('must be a positive integer')) {\n    console.error(`Fix ${e.message.split(' ')[0]} flag`);\n  }\n  throw e;\n}","preventionTips":["Rely on defaults (limit 25, depth 2, replies 5) instead of hand-set values","Coerce/parse flags with Number.parseInt and validate before invoking","Never pass 0 or negative values expecting 'unlimited' — use --depth 1 for no replies","Add pre-flight checks in wrapper scripts"],"tags":["validation","cli-arguments","input-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}