{"record":{"id":"d5fe9aa6d246de6d","repo":"jackwener/OpenCLI","slug":"tvmaze-label-must-be-a-positive-integer","errorCode":null,"errorMessage":"tvmaze ${label} must be a positive integer","messagePattern":"tvmaze (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/tvmaze/utils.js","lineNumber":32,"sourceCode":"}\n\nexport function requireShowId(value) {\n    const raw = value;\n    const n = typeof raw === 'number' ? raw : Number(String(raw ?? '').trim());\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(\n            'tvmaze show id is required and must be a positive integer',\n            'TVmaze show ids appear in the URL: https://www.tvmaze.com/shows/<id>/<slug>.',\n        );\n    }\n    return n;\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(`tvmaze ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`tvmaze ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport async function tvmazeFetch(url, label) {\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that api.tvmaze.com is reachable from this network.',\n        );\n    }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tvmaze/utils.js#L14-L50","documentation":"requireBoundedInt validates a numeric CLI option (by default 'limit') and throws ArgumentError when the value is not a positive integer. The tvmaze CLI uses it to sanitize user-supplied paging limits before building the API request URL. This error means the value passed (or its string form) failed Number.isInteger or was <= 0.","triggerScenarios":"Passing --limit values like 0, -5, 2.5, 'abc', '10px', or an empty string to a tvmaze list/show command; also passing a numeric string with whitespace that Number() coerces to NaN.","commonSituations":"Typo in a script (limit=0 to mean 'unlimited'), shell variables that are unset or contain unit suffixes ('25 results'), or copying fractional values from a config file.","solutions":["Pass a whole number >= 1 (e.g. --limit 10)","Omit the option entirely so the defaultValue is used","Trim/validate any shell or config value before passing it; coerce with Number() and check Number.isInteger yourself","If you need 'no limit', use the maximum allowed value rather than 0"],"exampleFix":"// before\ncli --limit 0\n// after\ncli --limit 10   # or omit --limit to use the default","handlingStrategy":"validation","validationCode":"function safeLimit(value, def = 10, max = 250) {\n  if (value === undefined || value === null) return def;\n  const n = Number(value);\n  if (!Number.isInteger(n) || n <= 0 || n > max) {\n    throw new RangeError(`limit must be an integer in [1, ${max}], got: ${value}`);\n  }\n  return n;\n}\n// call before the command: safeLimit(process.env.LIMIT)","typeGuard":"function isPositiveInt(v) {\n  return typeof v === 'number'\n    ? Number.isInteger(v) && v > 0\n    : Number.isInteger(Number(v)) && Number(v) > 0;\n}","tryCatchPattern":"try {\n  await cli(['tvmaze', 'list', '--limit', String(limit)]);\n} catch (err) {\n  if (err.name === 'ArgumentError' && /must be a positive integer/.test(err.message)) {\n    console.error(`Invalid --limit '${limit}'; using default.`);\n  } else throw err;\n}","preventionTips":["Validate numeric options with Number.isInteger at the entry point of your script","Never use 0 or negative numbers as 'unlimited'; use the documented max","Trim and sanitize env/config values before passing them to CLI flags"],"tags":["validation","cli","arguments","input-validation"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}