jackwener/OpenCLI · error · ArgumentError
${name} must be a positive integer
Error message
${name} must be a positive integer What it means
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.
Source
Thrown at clis/tiktok/utils.js:27
import {
ArgumentError,
AuthRequiredError,
CommandExecutionError,
EmptyResultError,
getErrorMessage,
} from '@jackwener/opencli/errors';
export const TIKTOK_AID = '1988';
export const TIKTOK_HOST = 'https://www.tiktok.com';
export const SERVER_PAGE_MAX = 30;
export const MAX_PAGES = 4;
export function requireLimit(value, { fallback, max, name = 'limit' }) {
const raw = value ?? fallback;
const parsed = Number(raw);
if (!Number.isInteger(parsed) || parsed <= 0) {
throw new ArgumentError(
`${name} must be a positive integer`,
`Example: --${name} ${fallback}`,
);
}
if (parsed > max) {
throw new ArgumentError(
`${name} must be <= ${max}`,
`Example: --${name} ${max}`,
);
}
return parsed;
}
export function normalizeUsername(value) {
const username = String(value ?? '').trim().replace(/^@+/, '');
if (!username) {
throw new ArgumentError(
'username is required',View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before opencli tiktok user someone --limit 0 // after opencli tiktok user someone --limit 10
Defensive patterns
Strategy: validation
Validate before calling
function isValidLimit(v) {
const n = Number(v);
return Number.isInteger(n) && n > 0;
}
const limit = process.argv.flagLimit;
if (limit !== undefined && !isValidLimit(limit)) throw new Error(`limit must be a positive integer, got: ${JSON.stringify(limit)}`); Type guard
const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0;
Try / catch
try {
await cli.tiktok.user(username, { limit });
} catch (e) {
if (/must be a positive integer/.test(e.message)) {
console.error(`Bad --limit value ${limit!r}; use a positive integer like 10`);
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
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
- coingecko derivatives limit must be a positive integer
- ${label} must be a positive integer
- ${label} must be an integer >= ${min}
- medium tag "${value}" is not valid
- ${name} must be <= ${max}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/43b31e093eb6443c.
Report an issue: GitHub.