jackwener/OpenCLI · error · ArgumentError
--limit must be a positive integer, got ${parsed}
Error message
--limit must be a positive integer, got ${parsed} What it means
parseLimit throws ArgumentError when the value coerces to a finite integer but is below the allowed minimum of 1 (e.g. 0, -5). The message embeds the coerced number rather than the raw input, distinguishing it from the non-integer branch of the same guard.
Source
Thrown at clis/rednote/notifications.js:31
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
const NOTIFICATION_TYPES = new Set(['mentions', 'likes', 'connections']);
function parseNotificationType(raw) {
const type = String(raw ?? 'mentions');
if (!NOTIFICATION_TYPES.has(type)) {
throw new ArgumentError(`--type must be one of mentions, likes, or connections, got ${JSON.stringify(raw)}`);
}
return type;
}
function parseLimit(raw) {
const parsed = Number(raw ?? 20);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--limit must be a positive integer, got ${JSON.stringify(raw)}`);
}
if (parsed < 1) {
throw new ArgumentError(`--limit must be a positive integer, got ${parsed}`);
}
return parsed;
}
const READ_NOTIFICATIONS_JS = `
(async (type) => {
let pinia = null;
const probe = (el) => el?.__vue_app__?.config?.globalProperties?.$pinia ?? null;
pinia = probe(document.querySelector('#app'));
if (!pinia) {
for (const el of document.querySelectorAll('*')) {
pinia = probe(el);
if (pinia) break;
}
}
if (!pinia || !pinia._s) return { error: 'no_pinia' };
const store = pinia._s.get('notification');
if (!store) return { error: 'no_notification_store' };View on GitHub (pinned to 49907e53dc)
Solutions
- Pass --limit with a value of at least 1
- If 0 should mean 'unlimited', clamp before invoking: Math.max(1, parsed)
- Check scripts computing the limit dynamically for arithmetic that can produce 0 or negatives
Example fix
// before const limit = items.length; // can be 0 run(['rednote','notifications','--limit', limit]); // after const limit = Math.max(1, items.length); run(['rednote','notifications','--limit', limit]);
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(raw ?? 20); if (Number.isInteger(n) && n < 1) throw new Error(`--limit must be >= 1, got ${n}`); Type guard
const isPositiveInt = (v) => Number.isInteger(v) && v >= 1;
Try / catch
try { await runNotifications({ limit }); } catch (e) { if (e instanceof ArgumentError && /positive integer/.test(e.message)) { limit = Math.max(1, limit); return runNotifications({ limit }); } throw e; } Prevention
- Never use 0 to mean 'unlimited'; clamp with Math.max(1, n)
- Check arithmetic that computes limits for values that can reach 0 or below
- Document limit semantics in scripts that wrap the CLI
When it happens
Trigger: Passing --limit 0 or a negative integer (e.g. --limit -1) to the rednote notifications command. Note that '0' as a string coerces to 0 and lands here, not in the non-integer branch.
Common situations: Config files or scripts that compute a limit via subtraction or slicing math that yields 0, users who think 0 means 'unlimited', or off-by-one loop calculations passed through to the CLI.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- ${label} must be between ${min} and ${max}, got ${parsed}
- ${label} must be <= ${max}
- --${name} must be between ${min} and ${max}, got ${parsed}
- flomo memos --${name} must be between 1 and ${max}
- limit must be an integer between 1 and ${max}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d46ef34c55afd5ba.
Report an issue: GitHub.