{"record":{"id":"5da7b354f2e451b7","repo":"jackwener/OpenCLI","slug":"name-must-be-max-5da7b3","errorCode":null,"errorMessage":"${name} must be <= ${max}","messagePattern":"(.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/tiktok/utils.js","lineNumber":33,"sourceCode":"    getErrorMessage,\n} from '@jackwener/opencli/errors';\n\nexport const TIKTOK_AID = '1988';\nexport const TIKTOK_HOST = 'https://www.tiktok.com';\nexport const SERVER_PAGE_MAX = 30;\nexport const MAX_PAGES = 4;\n\nexport function requireLimit(value, { fallback, max, name = 'limit' }) {\n    const raw = value ?? fallback;\n    const parsed = Number(raw);\n    if (!Number.isInteger(parsed) || parsed <= 0) {\n        throw new ArgumentError(\n            `${name} must be a positive integer`,\n            `Example: --${name} ${fallback}`,\n        );\n    }\n    if (parsed > max) {\n        throw new ArgumentError(\n            `${name} must be <= ${max}`,\n            `Example: --${name} ${max}`,\n        );\n    }\n    return parsed;\n}\n\nexport function normalizeUsername(value) {\n    const username = String(value ?? '').trim().replace(/^@+/, '');\n    if (!username) {\n        throw new ArgumentError(\n            'username is required',\n            'Example: opencli tiktok following <username>',\n        );\n    }\n    if (!/^[A-Za-z0-9._-]+$/.test(username)) {\n        throw new ArgumentError(\n            'username contains unsupported characters',","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/utils.js#L15-L51","documentation":"After validating positivity and integrality, requireLimit rejects values greater than the configured max and throws this ArgumentError. The cap (e.g. MAX_PAGES = 4 upstream) exists to bound how many pages the CLI will fetch, keeping runtime and rate-limit exposure predictable.","triggerScenarios":"Passing a flag value above the option's maximum, e.g. --limit 50 when max is 20, or requesting more pages than MAX_PAGES allows; constructing limits dynamically (items.length) without clamping.","commonSituations":"Users assuming 'more is better' and setting very large limits; scripts that pass an unbounded page count from config; misreading which unit the flag uses (items vs pages) leading to inflated values.","solutions":["Lower the value to at most the stated max (the error's example shows the max, e.g. --limit <max>).","If you need more data, paginate: call the command repeatedly, or use cursor/offset options if available.","Clamp programmatic values: Math.min(requested, max) before invoking.","Check the command's help output for the option's documented maximum."],"exampleFix":"// before\nopencli tiktok user someone --limit 100\n// after (max enforced by the CLI, paginate instead)\nopencli tiktok user someone --limit 4\nopencli tiktok user someone --limit 4 --cursor <next>","handlingStrategy":"validation","validationCode":"function clampLimit(v, max) {\n  const n = Number(v);\n  if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');\n  return Math.min(n, max); // enforce max BEFORE calling the CLI\n}","typeGuard":"const withinMax = (v, max) => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) <= max;","tryCatchPattern":"try {\n  await cli.tiktok.user(username, { limit });\n} catch (e) {\n  const m = /must be <= (\\d+)/.exec(e.message);\n  if (m) {\n    const max = Number(m[1]);\n    await cli.tiktok.user(username, { limit: Math.min(limit, max) });\n  } else throw e;\n}","preventionTips":["Parse the allowed max from the error message or --help and clamp before calling","Paginate (repeat calls / cursors) instead of requesting oversized limits","Never derive limit flags from unbounded values like array lengths without Math.min","Confirm the flag's unit (items vs pages) to avoid inflated values"],"tags":["validation","argument-error","cli","input-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}