jackwener/OpenCLI · error · ArgumentError
--limit must be a positive integer, got ${JSON.stringify(kwa
Error message
--limit must be a positive integer, got ${JSON.stringify(kwargs.limit)} What it means
validateHashtagArgs coerces kwargs.limit with Number(limit ?? 10) and requires a positive integer. Non-integer, zero, negative, or NaN values produce an ArgumentError echoing the JSON-encoded input so the bad value is visible.
Source
Thrown at clis/douyin/hashtag.js:25
}
function requireListField(res, field, action) {
if (!isPlainObject(res)) {
throw new CommandExecutionError(`douyin hashtag ${action}: API returned malformed payload`);
}
const list = res[field];
if (list === undefined || list === null) return [];
if (!Array.isArray(list)) {
throw new CommandExecutionError(`douyin hashtag ${action}: API returned malformed "${field}"`);
}
return list;
}
function validateHashtagArgs(kwargs) {
const action = kwargs.action;
const limit = Number(kwargs.limit ?? 10);
if (!Number.isInteger(limit) || limit < 1) {
throw new ArgumentError(`--limit must be a positive integer, got ${JSON.stringify(kwargs.limit)}`);
}
if (action === 'search') {
const keyword = String(kwargs.keyword ?? '').trim();
if (!keyword) {
throw new ArgumentError('douyin hashtag search 需要 --keyword <关键词>', '示例: opencli douyin hashtag search --keyword 美食');
}
return;
}
if (action === 'suggest') {
const cover = String(kwargs.cover ?? '').trim();
if (!cover) {
throw new ArgumentError('douyin hashtag suggest 需要 --cover <cover_uri>', 'suggest 基于已上传的视频封面做 AI 推荐, 不是关键词搜索. 关键词搜索请用 `douyin hashtag search --keyword <词>`.');
}
}
}
cli({
site: 'douyin',View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer, e.g. `--limit 10`
- Fix the script variable: use `${LIMIT:-10}` or validate before invoking
- Omit --limit entirely to use the default of 10
Example fix
// before
opencli douyin hashtag search --keyword 美食 --limit $LIMIT // LIMIT empty → 0
// after
opencli douyin hashtag search --keyword 美食 --limit "${LIMIT:-10}" Defensive patterns
Strategy: validation
Validate before calling
const limit = Number(process.argv.limit ?? 10);
if (!Number.isInteger(limit) || limit < 1) throw new Error(`--limit must be a positive integer, got ${limit}`); Type guard
const isValidLimit = (v) => Number.isInteger(Number(v)) && Number(v) >= 1;
Try / catch
try {
await cli.hashtag({ action: 'search', keyword, limit });
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('--limit')) {
await cli.hashtag({ action: 'search', keyword, limit: 10 }); // default
} else throw e;
} Prevention
- Quote and default shell variables: --limit "${LIMIT:-10}"
- Never pass user input to --limit without integer validation
- Omit --limit to accept the built-in default of 10
When it happens
Trigger: Passing `--limit 0`, `--limit -5`, `--limit abc`, `--limit 2.5`, or `--limit ""` to `douyin hashtag list/search/suggest`. Number('') is 0 and Number(undefined) falls back to 10, so empty strings and garbage both fail here.
Common situations: Shell scripts with unquoted/empty variables (`--limit $LIMIT` where LIMIT is unset), copy-pasted fractional values, or users assuming limit is optional-but-zero means unlimited.
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
- `endoflife ${label} must be <= ${maxValue}`
- facebook search --limit must be an integer between 1 and ${M
- facebook search requires a non-empty query
- ${label} must be a path/URL or a JSON array: ${errorMessage(
- ${name} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8b57786cc3fa26f2.
Report an issue: GitHub.