{"record":{"id":"43b31e093eb6443c","repo":"jackwener/OpenCLI","slug":"name-must-be-a-positive-integer-43b31e","errorCode":null,"errorMessage":"${name} must be a positive integer","messagePattern":"(.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/tiktok/utils.js","lineNumber":27,"sourceCode":"\nimport {\n    ArgumentError,\n    AuthRequiredError,\n    CommandExecutionError,\n    EmptyResultError,\n    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',","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/utils.js#L9-L45","documentation":"requireLimit normalizes a numeric option (value ?? fallback) with Number() and throws this ArgumentError when the result is not an integer or is <= 0. The CLI enforces it so pagination flags like --limit never receive nonsense such as 0, negatives, decimals, or non-numeric strings.","triggerScenarios":"Passing --limit 0, a negative value, a float like 2.5, or a non-numeric string; passing an empty string (Number('') is 0); passing whitespace like ' ' (Number(' ') is 0).","commonSituations":"Shell variables that expand to empty strings (LIMIT=\"\" -> --limit \"\"); copying example values that include units ('10 pages'); typos like '--limit l0'; scripts defaulting counters to 0 and forwarding them as limits.","solutions":["Pass a positive integer, e.g. --limit 10 (the error's example hint shows the fallback to use).","Omit the flag entirely to use the built-in fallback value.","Fix the shell variable so it does not expand to an empty string: use \"${LIMIT:-10}\".","Sanitize any programmatic input with Number.isInteger before invoking the command."],"exampleFix":"// before\nopencli tiktok user someone --limit 0\n// after\nopencli tiktok user someone --limit 10","handlingStrategy":"validation","validationCode":"function isValidLimit(v) {\n  const n = Number(v);\n  return Number.isInteger(n) && n > 0;\n}\nconst limit = process.argv.flagLimit;\nif (limit !== undefined && !isValidLimit(limit)) throw new Error(`limit must be a positive integer, got: ${JSON.stringify(limit)}`);","typeGuard":"const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0;","tryCatchPattern":"try {\n  await cli.tiktok.user(username, { limit });\n} catch (e) {\n  if (/must be a positive integer/.test(e.message)) {\n    console.error(`Bad --limit value ${limit!r}; use a positive integer like 10`);\n  } else throw e;\n}","preventionTips":["Default shell vars: \"${LIMIT:-10}\" so they never expand empty","Never pass 0, negatives, floats, or non-numeric strings as limit flags","Clamp and coerce with Number() + Number.isInteger before invoking","Omit the flag to accept the CLI's built-in fallback"],"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-29T12:17:43.993Z"}