jackwener/OpenCLI · error · ArgumentError

twitter following --limit must be a positive integer

Error message

twitter following --limit must be a positive integer

What it means

ArgumentError thrown by the twitter following command when the --limit argument is not a positive integer. The command coerces the kwarg with Number() and requires Number.isInteger(limit) && limit > 0; anything else (0, negative, float, NaN, non-numeric string) fails validation before any browsing starts.

Source

Thrown at clis/twitter/following.js:143

    description: 'Get accounts a Twitter/X user is following (defaults to the logged-in user when no user is given)',
    domain: 'x.com',
    strategy: Strategy.COOKIE,
    browser: true,
    args: [
        {
            name: 'user',
            positional: true,
            type: 'string',
            required: false,
            help: 'Twitter/X handle (with or without @). Omit to fetch the accounts the currently logged-in user follows.',
        },
        { name: 'limit', type: 'int', default: 50, help: 'Maximum number of following rows to return (default 50). Must be a positive integer.' },
    ],
    columns: ['screen_name', 'name', 'bio', 'followers'],
    func: async (page, kwargs) => {
        const limit = kwargs.limit === undefined || kwargs.limit === null ? 50 : Number(kwargs.limit);
        if (!Number.isInteger(limit) || limit <= 0) {
            throw new ArgumentError('twitter following --limit must be a positive integer', 'Example: opencli twitter following @elonmusk --limit 200');
        }
        const rawUser = String(kwargs.user ?? '').trim();
        let targetUser = normalizeScreenName(rawUser);
        if (rawUser && !targetUser) {
            throw new ArgumentError('twitter following user must be a valid Twitter/X handle', 'Example: opencli twitter following @elonmusk --limit 200');
        }

        const cookies = await page.getCookies({ url: 'https://x.com' });
        const ct0 = cookies.find((c) => c.name === 'ct0')?.value || null;
        if (!ct0)
            throw new AuthRequiredError('x.com', 'Not logged into x.com (no ct0 cookie)');

        if (!targetUser) {
            // Force a navigation to the home surface so the AppTabBar sidebar
            // is rendered; the framework pre-nav lands on bare x.com which
            // does not always expose AppTabBar_Profile_Link.
            await page.goto('https://x.com/home');
            await page.wait({ selector: '[data-testid="primaryColumn"]' });

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass --limit as a positive whole number, e.g. --limit 200.
  2. Fix the calling script so the limit variable is set to a valid integer before invocation.
  3. Remove --limit entirely to use the default of 50.
  4. If a wrapper produces floats, Math.trunc/round the value and check Number.isInteger before calling.

Example fix

// before
opencli twitter following @elonmusk --limit 0
// after
opencli twitter following @elonmusk --limit 200
Defensive patterns

Strategy: validation

Validate before calling

function assertPositiveIntLimit(v, def = 50) {
  if (v === undefined || v === null) return def;
  const n = Number(v);
  if (!Number.isInteger(n) || n <= 0) {
    throw new Error(`--limit must be a positive integer, got: ${JSON.stringify(v)}`);
  }
  return n;
}
const limit = assertPositiveIntLimit(rawLimit);

Type guard

const isPositiveInt = (v) => Number.isInteger(v) && v > 0;

Try / catch

import { ArgumentError } from '@jackwener/opencli/errors';
try {
  rows = await opencli.twitter.following(user, { limit });
} catch (e) {
  if (e instanceof ArgumentError && /--limit must be a positive integer/.test(e.message)) {
    rows = await opencli.twitter.following(user, { limit: 50 }); // fall back to default
  } else throw e;
}

Prevention

When it happens

Trigger: Calling opencli twitter following with --limit 0, a negative number, a decimal like 50.5, a non-numeric string, or a value that coerces to NaN (e.g. --limit abc). kwargs.limit undefined/null defaults to 50 and does NOT trigger this.

Common situations: Shell quoting mistakes passing '50 100'; scripting with an unset variable that becomes an empty/invalid string; copy-pasting a float from config; using --limit 0 expecting 'unlimited'.

Related errors


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