jackwener/OpenCLI · warning · ArgumentError
weibo favorites ${name} must be a positive integer
Error message
weibo favorites ${name} must be a positive integer What it means
clis/weibo/favorites.js:12 — parsePositiveInt throws ArgumentError(`weibo favorites ${name} must be a positive integer`) when a numeric option (e.g. limit, called via the limit option handler) is not an integer or is <= 0. Defaults apply only when the value is nullish; any provided value must be a strictly positive integer. MAX_LIMIT is 50.
Source
Thrown at clis/weibo/favorites.js:12
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { getSelfUid, requireArrayEvaluateResult, unwrapEvaluateResult } from './utils.js';
const DEFAULT_LIMIT = 20;
const MAX_LIMIT = 50;
function parsePositiveInt(value, name, defaultValue) {
const raw = value ?? defaultValue;
const number = Number(raw);
if (!Number.isInteger(number) || number <= 0) {
throw new ArgumentError(`weibo favorites ${name} must be a positive integer`);
}
if (number > MAX_LIMIT) {
throw new ArgumentError(`weibo favorites ${name} must be <= ${MAX_LIMIT}`);
}
return number;
}
function parseFavoriteCard(card, favUrl) {
const raw = String(card?.text ?? '');
const lines = raw.split('\n');
let author = '';
let time = '';
let source = '';
let content = '';
let likes = '0';
let comments = '0';
let reposts = '0';View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer, e.g. limit: 20 (omit the option entirely to use the default)
- Coerce and validate user/config input before the call: Number(value) and Number.isInteger check
- Trim numeric strings; empty string is not a valid value — drop it so the default applies
- Remember the hard cap is 50; larger values need the <=50 error (see next entry)
Example fix
// before
await cli.run('weibo favorites', { limit: '20 ' }); // ArgumentError
// after
const n = Number(String(cfg.limit ?? '').trim());
await cli.run('weibo favorites', { limit: Number.isInteger(n) && n > 0 ? n : undefined }); Defensive patterns
Strategy: validation
Validate before calling
function toPositiveInt(v, fallback = 20) {
if (v == null || v === '') return fallback;
const n = Number(v);
return Number.isInteger(n) && n > 0 ? n : fallback;
} Type guard
function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v > 0; } Try / catch
try {
await cli.run('weibo favorites', { limit });
} catch (e) {
if (e instanceof Error && /must be a positive integer/.test(e.message)) {
console.error(`limit must be a positive integer, got: ${JSON.stringify(limit)}`);
}
throw e;
} Prevention
- Coerce config/env strings with Number() and trim whitespace before passing
- Drop empty values so the CLI default (20) applies
- Reject 0 early — the CLI treats it as invalid, not 'unlimited'
- Unit-test option parsing in scripts that build CLI args dynamically
When it happens
Trigger: Calling `weibo favorites` with limit=0, a negative number, a non-integer like 2.5, or a non-numeric string such as limit="abc" or "" (Number('') is 0).
Common situations: Users passing 0 expecting 'unlimited'; config/env strings like '20 ' or 'twenty' not being pre-parsed; scripts interpolating empty variables into limit; fractional values from dividing counts.
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
- weibo favorites ${name} must be <= ${MAX_LIMIT}
- weibo publish text cannot be empty
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9c0cdb0e115644f1.
Report an issue: GitHub.