{"record":{"id":"fd934df61c7951f4","repo":"jackwener/OpenCLI","slug":"tvmaze-label-must-be-maxvalue","errorCode":null,"errorMessage":"tvmaze ${label} must be <= ${maxValue}","messagePattern":"tvmaze (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/tvmaze/utils.js","lineNumber":35,"sourceCode":"    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    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `TVmaze returned 404 for ${url}.`);\n    }","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tvmaze/utils.js#L17-L53","documentation":"requireBoundedInt enforces an upper bound (maxValue) on numeric options and throws ArgumentError when the value exceeds it. TVmaze caps page sizes/results per request, so limits above the API maximum are rejected before a request is wasted. This error means the value was a valid positive integer but larger than maxValue.","triggerScenarios":"Calling a tvmaze command with --limit above the endpoint's maximum (e.g. limit 100 when maxValue is 20 or 250 depending on the command).","commonSituations":"Reusing a limit tuned for another API, assuming 'bigger is fine', or misreading the endpoint's documented max results per page.","solutions":["Lower the limit to <= the stated maximum (the message shows the exact maxValue)","If you need more items, page through results with repeated calls instead of one oversized request","Check the command's help text for the accepted range"],"exampleFix":"// before\ncli --limit 500\n// after\ncli --limit 250  // or the maxValue printed in the error","handlingStrategy":"validation","validationCode":"function clampLimit(value, max) {\n  const n = Number(value);\n  if (!Number.isInteger(n) || n <= 0) return undefined; // let default apply\n  return Math.min(n, max);\n}\n// e.g. const limit = clampLimit(userLimit, 250);","typeGuard":"function isWithinBounds(v, max) {\n  const n = Number(v);\n  return Number.isInteger(n) && n > 0 && n <= max;\n}","tryCatchPattern":"try {\n  await cli(['tvmaze', 'list', '--limit', String(limit)]);\n} catch (err) {\n  if (err.name === 'ArgumentError' && /must be <= /.test(err.message)) {\n    const max = Number(err.message.match(/<= (\\d+)/)?.[1]);\n    console.error(`--limit too high; max is ${max}.`);\n  } else throw err;\n}","preventionTips":["Check the command's help/README for the maximum limit per endpoint","Clamp user input with Math.min(n, max) instead of passing it raw","Page through results for large datasets rather than raising the limit"],"tags":["validation","cli","arguments","rate-limits"],"backgroundTag":"parameter-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}