jackwener/OpenCLI · error · Error

limit must be a positive integer

Error message

limit must be a positive integer

What it means

Identical input validation to the followers CLI but in the following command's embedded script: --limit must be a positive integer before any fetch occurs. The value is interpolated into the evaluate script and immediately checked with Number.isInteger(limit) && limit >= 1, guarding the paginated count parameter (PAGE_SIZE 50) and loop termination.

Source

Thrown at clis/instagram/following.js:19

import { cli } from '@jackwener/opencli/registry';
import { buildResolveInstagramUserIdJs } from './_shared/user-id.js';
cli({
    site: 'instagram',
    name: 'following',
    access: 'read',
    description: 'List accounts an Instagram user is following',
    domain: 'www.instagram.com',
    args: [
        { name: 'username', required: true, positional: true, help: 'Instagram username' },
        { name: 'limit', type: 'int', default: 20, help: 'Number of accounts' },
    ],
    columns: ['rank', 'username', 'name', 'verified', 'private'],
    pipeline: [
        { navigate: 'https://www.instagram.com' },
        { evaluate: `(async () => {
  const username = \${{ args.username | json }};
  const limit = \${{ args.limit }};
  if (!Number.isInteger(limit) || limit < 1) throw new Error('limit must be a positive integer');
  const headers = { 'X-IG-App-ID': '936619743392459' };
  const opts = { credentials: 'include', headers };

  ${buildResolveInstagramUserIdJs()}

  const PAGE_SIZE = 50;
  const results = [];
  const seen = new Set();
  const seenCursors = new Set();
  let maxId = undefined;
  const baseUrl = 'https://www.instagram.com/api/v1/friendships/' + userId + '/following/';

  while (results.length < limit) {
    const params = new URLSearchParams({ count: String(PAGE_SIZE) });
    if (maxId) params.set('max_id', maxId);
    const r2 = await fetch(baseUrl + '?' + params.toString(), opts);
    if (!r2.ok) throw new Error('Failed to fetch following: HTTP ' + r2.status);
    const d2 = await r2.json();

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer, e.g. --limit 50.
  2. Sanitize in the calling script: parseInt then validate Number.isInteger(n) && n > 0.
  3. Omit the flag to use the default if available.
  4. Fix upstream config/wrapper so numeric values stay numeric through interpolation.

Example fix

// before
opencli instagram following someuser --limit -5
// after
const limit = Math.trunc(Number(raw));
if (!Number.isInteger(limit) || limit < 1) throw new Error('limit must be a positive integer');
Defensive patterns

Strategy: validation

Validate before calling

function coercePositiveInt(raw) {
  const n = typeof raw === 'number' ? raw : Number.parseInt(raw, 10);
  if (!Number.isInteger(n) || n < 1) throw new Error('limit must be a positive integer');
  return n;
}
// call before invoking the following command

Type guard

function isPositiveInt(v) { return Number.isInteger(v) && v >= 1; }

Try / catch

try {
  await cli.following(username, limit);
} catch (e) {
  if (String(e.message).includes('limit must be')) {
    console.error('Pass --limit as a positive integer, e.g. --limit 50');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking the following command with limit=0, negative values, decimals, or a non-numeric interpolated value (string/NaN) from a wrapper or config file.

Common situations: Scripts passing string '20' or empty limit; users expecting 0 to mean 'all'; config files supplying floats or blank values; Shell quoting turning the number into a string.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/b82e30f1748bd59a. Report an issue: GitHub.