jackwener/OpenCLI · error · ArgumentError
${label} must be a positive integer
Error message
${label} must be a positive integer What it means
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.
Source
Thrown at clis/tiktok/creator-videos.js:20
import {
ArgumentError,
AuthRequiredError,
CommandExecutionError,
EmptyResultError,
getErrorMessage,
} from '@jackwener/opencli/errors';
const STUDIO_CONTENT_URL = 'https://www.tiktok.com/tiktokstudio/content';
const ITEM_LIST_API_PATH = '/tiktok/creator/manage/item_list/v1/';
const DEFAULT_LIMIT = 20;
const MAX_LIMIT = 250;
const SERVER_PAGE_MAX = 50;
function requirePositiveInt(value, label, defaultValue, maxValue) {
const raw = value ?? defaultValue;
const parsed = Number(raw);
if (!Number.isInteger(parsed) || parsed <= 0) {
throw new ArgumentError(`${label} must be a positive integer`, `Example: opencli tiktok creator-videos --${label} ${defaultValue}`);
}
if (parsed > maxValue) {
throw new ArgumentError(`${label} must be <= ${maxValue}`, `Example: opencli tiktok creator-videos --${label} ${maxValue}`);
}
return parsed;
}
function requireCursor(value) {
const raw = value ?? '0';
const text = String(raw).trim();
if (!/^\d+$/.test(text)) {
throw new ArgumentError('cursor must be a non-negative integer string', 'Example: opencli tiktok creator-videos --cursor 0');
}
const cursor = Number(text);
if (!Number.isSafeInteger(cursor)) {
throw new ArgumentError('cursor must be a safe integer', 'Example: opencli tiktok creator-videos --cursor 0');
}
return cursor;View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before opencli tiktok creator-videos --limit 0 // after opencli tiktok creator-videos --limit 20
Defensive patterns
Strategy: validation
Validate before calling
const limit = Number(process.env.TT_LIMIT ?? 20);
if (!Number.isInteger(limit) || limit <= 0) {
throw new Error(`--limit must be a positive integer, got: ${process.env.TT_LIMIT}`);
}
await run(['tiktok', 'creator-videos', '--limit', String(limit)]); Type guard
const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0;
Try / catch
try {
await run(['tiktok', 'creator-videos', '--limit', raw]);
} catch (e) {
if (String(e.message).includes('must be a positive integer')) {
console.error(`Bad --limit '${raw}'; use e.g. --limit 20`);
process.exitCode = 2;
} else throw e;
} Prevention
- 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.
When it happens
Trigger: Running `opencli tiktok creator-videos --limit 0`, `--limit -5`, `--limit abc`, `--limit 3.5`, or passing an empty/undefined value with no default.
Common situations: 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'.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ${label} must be <= ${maxValue}
- cursor must be a non-negative integer string
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8d2f62715254380c.
Report an issue: GitHub.