{"record":{"id":"80796e4d099eac35","repo":"jackwener/OpenCLI","slug":"flathub-label-must-be-a-positive-integer","errorCode":null,"errorMessage":"flathub ${label} must be a positive integer","messagePattern":"flathub (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/flathub/utils.js","lineNumber":27,"sourceCode":"export const FLATHUB_API_BASE = 'https://flathub.org/api/v2';\nexport const FLATHUB_APP_BASE = 'https://flathub.org/apps';\nconst UA = 'opencli-flathub-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';\n\n// AppStream IDs are reverse-DNS (e.g. \"org.gnome.Calculator\"); the spec allows\n// letters, digits, `.`, `_`, `-`. Min two segments separated by `.`.\nconst APP_ID_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*(?:\\.[A-Za-z0-9_][A-Za-z0-9_-]*){1,}$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`flathub ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\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(`flathub ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`flathub ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireAppId(value) {\n    const raw = String(value ?? '').trim();\n    if (!raw) throw new ArgumentError('flathub appId is required (e.g. \"org.mozilla.firefox\")');\n    if (!APP_ID_PATTERN.test(raw)) {\n        throw new ArgumentError(\n            `flathub appId \"${value}\" is not a valid AppStream identifier`,\n            'AppStream IDs use reverse-DNS like \"org.mozilla.firefox\" — letters/digits/`._-` with at least one dot.',\n        );\n    }\n    return raw;\n}","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/flathub/utils.js#L9-L45","documentation":"requireBoundedInt validates that a numeric option (labelled, default 'limit') is a positive integer; it throws ArgumentError with 'flathub <label> must be a positive integer' when the value is not an integer or is <= 0. This guards the limit/pagination option before it is sent to the Flathub API.","triggerScenarios":"Passing a limit of 0, a negative number, a non-integer float (e.g. 2.5), or a string that fails Number() conversion (NaN), such as requireBoundedInt('abc', 10, 50) or requireBoundedInt(0, 10, 50).","commonSituations":"CLI invoked with --limit 0 or a typo like --limit 1o; config file holding a string like 'ten'; parsing user input without validation; JSON config where the value is a float.","solutions":["Pass a positive integer for the option (e.g. --limit 10)","Use the default by omitting the option entirely","Coerce/validate the value with Number.isInteger(Number(v)) && v > 0 before calling","Fix typos or string values in the config or shell variable"],"exampleFix":"// before\nawait searchApps(query, { limit: 'ten' });\n// after\nawait searchApps(query, { limit: 10 });","handlingStrategy":"validation","validationCode":"function isValidLimit(v) {\n  const n = typeof v === 'number' ? v : Number(v);\n  return Number.isInteger(n) && n > 0;\n}\nif (!isValidLimit(opts.limit)) throw new Error('limit must be a positive integer');","typeGuard":"function isPositiveInt(v) {\n  const n = typeof v === 'number' ? v : Number(v);\n  return Number.isInteger(n) && n > 0;\n}","tryCatchPattern":"try {\n  await searchApps(query, { limit });\n} catch (err) {\n  if (err instanceof ArgumentError && /positive integer/.test(err.message)) {\n    console.error('Bad --limit value; use a positive integer like 10');\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Parse numeric CLI flags with a strict parser rather than free-form strings","Validate Number.isInteger and > 0 on user-supplied numbers before calls","Avoid copy-pasting option values from configs without checking types","Prefer omitting the option to use the library default"],"tags":["argument-validation","input-error","numeric-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}