jackwener/OpenCLI · error · ArgumentError

facebook marketplace-listings --limit must be a positive int

Error message

facebook marketplace-listings --limit must be a positive integer

What it means

ArgumentError from normalizeLimit when the --limit value for facebook marketplace-listings is not a positive integer. The helper coerces the arg with Number() and rejects NaN, non-integers, zero and negatives before clamping to 100. It validates input early so the command never runs with a nonsensical limit.

Source

Thrown at clis/facebook/marketplace-listings.js:7

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';

function normalizeLimit(value) {
  const limit = Number(value ?? 20);
  if (!Number.isInteger(limit) || limit <= 0) {
    throw new ArgumentError('facebook marketplace-listings --limit must be a positive integer');
  }
  return Math.min(limit, 100);
}

cli({
  site: 'facebook',
  name: 'marketplace-listings',
    access: 'read',
  description: 'List your Facebook Marketplace seller listings',
  domain: 'www.facebook.com',
  strategy: Strategy.COOKIE,
  args: [
    { name: 'limit', type: 'int', default: 20, help: 'Number of listings to return' },
  ],
  columns: ['index', 'title', 'price', 'status', 'listed', 'clicks', 'actions'],
  func: async (page, args) => {
    if (!page) throw new CommandExecutionError('Browser session required for facebook marketplace-listings');
    const limit = normalizeLimit(args.limit);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer, e.g. `--limit 20` (max 100)
  2. Validate the value before invoking the CLI: Number.isInteger(limit) && limit > 0
  3. If using a shell variable, ensure it is set and numeric; unset vars become NaN
  4. Drop the flag entirely to use the default of 20

Example fix

// before
cli --site facebook marketplace-listings --limit 0
// after
cli --site facebook marketplace-listings --limit 20
Defensive patterns

Strategy: validation

Validate before calling

function validateLimit(raw) {
  const n = Number(raw);
  if (!Number.isInteger(n) || n <= 0) throw new Error(`--limit must be a positive integer, got ${JSON.stringify(raw)}`);
  return Math.min(n, 100);
}

Type guard

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

Try / catch

try {
  await runMarketplaceListings({ limit });
} catch (e) {
  if (/--limit must be a positive integer/.test(e.message)) {
    console.error('Bad --limit; using default 20');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the CLI with `--limit 0`, `--limit -5`, `--limit abc`, `--limit 2.5`, or any value that Number() cannot turn into a positive integer.

Common situations: Typo like `--limit=twenty`; shell variable expanding empty/undefined then being coerced to NaN (note: empty string coerces to 0, which also fails); scripting with user-supplied values not validated upstream.

Related errors


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