{"record":{"id":"4ecf7ad21dd83c0f","repo":"jackwener/OpenCLI","slug":"label-must-be-an-integer-min-4ecf7a","errorCode":null,"errorMessage":"${label} must be an integer >= ${min}","messagePattern":"(.+?) must be an integer >= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hackernews/read.js","lineNumber":35,"sourceCode":"\nasync function fetchItem(id) {\n    const res = await fetch(`${HN_ITEM_BASE}/${id}.json`);\n    if (!res.ok) {\n        throw new CommandExecutionError(`HN API HTTP ${res.status} for item ${id}`, 'Check the item 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/** HN stores 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')\n        .replace(/<i>(.*?)<\\/i>/gi, '$1')\n        .replace(/<a[^>]*href=\"([^\"]*)\"[^>]*>(.*?)<\\/a>/gi, '$2 ($1)')\n        .replace(/<pre><code>([\\s\\S]*?)<\\/code><\\/pre>/gi, '\\n$1\\n')\n        .replace(/<[^>]+>/g, '')\n        .replace(/&#x27;/g, \"'\")\n        .replace(/&quot;/g, '\"')\n        .replace(/&lt;/g, '<')","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hackernews/read.js#L17-L53","documentation":"`requireMinInt` throws `ArgumentError` when a value is not an integer or falls below a configured minimum. For `hackernews read`, it enforces `--max-length >= 100`, ensuring comment bodies are never truncated below a usable size. It is thrown before any HN API request is made.","triggerScenarios":"Running `hackernews read <id> --max-length 50` (or any value < 100), a non-integer like `--max-length 99.5`, or a non-numeric value; `--max-length` sourced from an unset/empty shell variable parsed as invalid.","commonSituations":"Users trying to get very short comment snippets with `--max-length 0` or small values; config files with `max_length: 50` that predate the min-100 rule; scripts passing defaults of empty string.","solutions":["Set `--max-length` to an integer >= 100 (default is 2000)","Omit the flag to use the default of 2000 characters per comment body","If truncation to less than 100 chars is desired, post-process the output instead (e.g. pipe through `cut`/`head`)"],"exampleFix":"// before\nopencli hackernews read 39847301 --max-length 80\n// after\nopencli hackernews read 39847301 --max-length 100","handlingStrategy":"validation","validationCode":"const v = Number(process.env.HN_MAX_LENGTH ?? 2000);\nif (!Number.isInteger(v) || v < 100) {\n  throw new Error(`--max-length must be an integer >= 100, got: ${process.env.HN_MAX_LENGTH}`);\n}","typeGuard":"function isIntAtLeast(v, min) {\n  return typeof v === 'number' && Number.isInteger(v) && v >= min;\n}","tryCatchPattern":"try {\n  await run(['opencli', 'hackernews', 'read', id, '--max-length', String(ml)]);\n} catch (e) {\n  if (String(e.message).includes('must be an integer >=')) {\n    console.error('max-length below minimum 100; falling back to 2000');\n    await run(['opencli', 'hackernews', 'read', id]);\n  } else throw e;\n}","preventionTips":["Remember the documented minimum is 100 — clamp values with Math.max(100, value) before passing","Omit the flag when you want the 2000-char default","Post-truncate output yourself instead of lowering --max-length below the minimum"],"tags":["argument-error","cli","validation","input-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}