{"record":{"id":"66f67336137254a3","repo":"jackwener/OpenCLI","slug":"label-must-be-maxvalue-66f673","errorCode":null,"errorMessage":"${label} must be <= ${maxValue}","messagePattern":"(.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/tiktok/creator-videos.js","lineNumber":23,"sourceCode":"    CommandExecutionError,\n    EmptyResultError,\n    getErrorMessage,\n} from '@jackwener/opencli/errors';\n\nconst STUDIO_CONTENT_URL = 'https://www.tiktok.com/tiktokstudio/content';\nconst ITEM_LIST_API_PATH = '/tiktok/creator/manage/item_list/v1/';\nconst DEFAULT_LIMIT = 20;\nconst MAX_LIMIT = 250;\nconst SERVER_PAGE_MAX = 50;\n\nfunction requirePositiveInt(value, label, defaultValue, maxValue) {\n    const raw = value ?? defaultValue;\n    const parsed = Number(raw);\n    if (!Number.isInteger(parsed) || parsed <= 0) {\n        throw new ArgumentError(`${label} must be a positive integer`, `Example: opencli tiktok creator-videos --${label} ${defaultValue}`);\n    }\n    if (parsed > maxValue) {\n        throw new ArgumentError(`${label} must be <= ${maxValue}`, `Example: opencli tiktok creator-videos --${label} ${maxValue}`);\n    }\n    return parsed;\n}\n\nfunction requireCursor(value) {\n    const raw = value ?? '0';\n    const text = String(raw).trim();\n    if (!/^\\d+$/.test(text)) {\n        throw new ArgumentError('cursor must be a non-negative integer string', 'Example: opencli tiktok creator-videos --cursor 0');\n    }\n    const cursor = Number(text);\n    if (!Number.isSafeInteger(cursor)) {\n        throw new ArgumentError('cursor must be a safe integer', 'Example: opencli tiktok creator-videos --cursor 0');\n    }\n    return cursor;\n}\n\nfunction buildItemListRequest(cursor, size) {","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/creator-videos.js#L5-L41","documentation":"requirePositiveInt also enforces an upper bound: if the parsed value exceeds the caller-supplied maxValue it throws ArgumentError with this message. For creator-videos the server page size caps at 50 (SERVER_PAGE_MAX), so a limit above that cannot be satisfied by a single server page.","triggerScenarios":"Running `opencli tiktok creator-videos --limit 100` (or any value > 50) — parsed value is a positive integer but exceeds maxValue.","commonSituations":"Developers assuming the CLI will loop pages internally and pass a large limit; copying limits from other tools with higher caps; trying to fetch an entire catalog in one call.","solutions":["Use --limit 50 or less per request.","Paginate with the --cursor option to fetch more results across calls.","If a bulk export is needed, loop in a script: request page, take nextCursor, repeat until exhausted."],"exampleFix":"// before\nopencli tiktok creator-videos --limit 100\n// after\nopencli tiktok creator-videos --limit 50 --cursor 0\n# then repeat with --cursor <nextCursor>","handlingStrategy":"validation","validationCode":"const SERVER_PAGE_MAX = 50;\nconst limit = Math.min(Number(process.env.TT_LIMIT ?? 20), SERVER_PAGE_MAX);\nif (!Number.isInteger(limit) || limit <= 0) throw new Error('limit must be a positive integer <= 50');","typeGuard":"const isValidLimit = (v, max = 50) => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) <= max;","tryCatchPattern":"try {\n  await run(['tiktok', 'creator-videos', '--limit', String(limit)]);\n} catch (e) {\n  if (String(e.message).includes('must be <=')) {\n    console.error('Clamping limit to server max of 50 and retrying');\n    await run(['tiktok', 'creator-videos', '--limit', '50', '--cursor', '0']);\n  } else throw e;\n}","preventionTips":["Clamp requested page sizes to the server maximum (50) before invoking.","Use cursor pagination instead of oversized limits for bulk fetches.","Centralize the max-page-size constant in your scripts."],"tags":["argument-validation","cli","pagination","tiktok"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}