{"record":{"id":"8d2f62715254380c","repo":"jackwener/OpenCLI","slug":"label-must-be-a-positive-integer-8d2f62","errorCode":null,"errorMessage":"${label} must be a positive integer","messagePattern":"(.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/tiktok/creator-videos.js","lineNumber":20,"sourceCode":"import {\n    ArgumentError,\n    AuthRequiredError,\n    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;","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/creator-videos.js#L2-L38","documentation":"requirePositiveInt validates numeric CLI options for the tiktok creator-videos command. It throws this ArgumentError when the provided value (or its default) is not an integer greater than 0 — e.g. missing, non-numeric, zero, negative, or fractional. The error includes an example invocation showing the expected flag and its default value.","triggerScenarios":"Running `opencli tiktok creator-videos --limit 0`, `--limit -5`, `--limit abc`, `--limit 3.5`, or passing an empty/undefined value with no default.","commonSituations":"Typos in the flag value; scripting with an empty environment variable that expands to nothing; passing a string with whitespace or units like '50 videos'; accidentally using 0 to mean 'all'.","solutions":["Pass a positive integer, e.g. --limit 20.","If reading from an env var or script, ensure the value is set and numeric before invoking the CLI.","Respect the server maximum (SERVER_PAGE_MAX = 50); use paging/cursor instead of a huge limit."],"exampleFix":"// before\nopencli tiktok creator-videos --limit 0\n// after\nopencli tiktok creator-videos --limit 20","handlingStrategy":"validation","validationCode":"const limit = Number(process.env.TT_LIMIT ?? 20);\nif (!Number.isInteger(limit) || limit <= 0) {\n  throw new Error(`--limit must be a positive integer, got: ${process.env.TT_LIMIT}`);\n}\nawait run(['tiktok', 'creator-videos', '--limit', String(limit)]);","typeGuard":"const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0;","tryCatchPattern":"try {\n  await run(['tiktok', 'creator-videos', '--limit', raw]);\n} catch (e) {\n  if (String(e.message).includes('must be a positive integer')) {\n    console.error(`Bad --limit '${raw}'; use e.g. --limit 20`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Validate numeric CLI inputs before passing them to the command.","Never pass 0 or negative values as page sizes; use cursor pagination for 'everything'.","Guard env-var-derived numbers with Number.isInteger checks."],"tags":["argument-validation","cli","tiktok"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}