jackwener/OpenCLI · error · ArgumentError

delay-ms must be an integer between 0 and ${MAX_DELAY_MS}

Error message

delay-ms must be an integer between 0 and ${MAX_DELAY_MS}

What it means

parseDelayMs validates the `--delay-ms` option and throws ArgumentError unless the value is an integer in [0, 60000]. Omitted, null, or empty-string inputs default to 3000ms; anything non-numeric, non-integer (1.5, '3s'), negative, or above 60000 throws. The cap prevents batch jobs from sleeping unboundedly between follows.

Source

Thrown at clis/twitter/follow-batch.js:122

    if (result.ok) {
        await page.wait(1);
    }

    return {
        username,
        status: result.ok ? result.status : 'failed',
        message: result.message,
    };
}

export function parseDelayMs(input) {
    if (input === undefined || input === null || input === '') {
        return DEFAULT_DELAY_MS;
    }
    const value = Number(input);
    if (!Number.isInteger(value) || value < 0 || value > MAX_DELAY_MS) {
        throw new ArgumentError(`delay-ms must be an integer between 0 and ${MAX_DELAY_MS}`);
    }
    return value;
}

cli({
    site: 'twitter',
    name: 'follow-batch',
    access: 'write',
    description: 'Follow multiple Twitter/X users from a comma-separated username list',
    domain: 'x.com',
    strategy: Strategy.UI,
    browser: true,
    args: [
        { name: 'usernames', type: 'string', positional: true, required: true, help: 'Comma-separated Twitter/X screen names, with or without @' },
        { name: 'delay-ms', type: 'int', default: DEFAULT_DELAY_MS, help: 'Delay between follow attempts in milliseconds' },
    ],
    columns: ['username', 'status', 'message'],
    func: async (page, kwargs) => {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a whole number of milliseconds between 0 and 60000: `--delay-ms 5000`.
  2. Convert seconds to milliseconds and clamp in scripts: Math.min(Math.max(Math.round(s*1000), 0), 60000).
  3. Omit the flag entirely to use the 3000ms default if no custom pacing is needed.
  4. Coerce with Number() and Number.isInteger() when reading values from config before calling.

Example fix

// before
opencli twitter follow-batch alice --delay-ms 5s
// after
opencli twitter follow-batch alice --delay-ms 5000
Defensive patterns

Strategy: validation

Validate before calling

function toValidDelayMs(input, { def = 3000, max = 60000 } = {}) {
  if (input === undefined || input === null || input === '') return def;
  const v = Number(input);
  if (!Number.isInteger(v) || v < 0 || v > max) {
    throw new RangeError(`delay-ms must be an integer between 0 and ${max}, got ${JSON.stringify(input)}`);
  }
  return v;
}

Type guard

function isValidDelayMs(v) {
  return v === undefined || v === null || v === '' ||
    (Number.isInteger(Number(v)) && Number(v) >= 0 && Number(v) <= 60000);
}

Try / catch

try {
  await followBatch(usernames, { 'delay-ms': rawDelay });
} catch (e) {
  if (e.code === 'ARGUMENT' && e.message.includes('delay-ms')) {
    console.error('Pass whole milliseconds 0-60000, e.g. --delay-ms 5000');
  } else throw e;
}

Prevention

When it happens

Trigger: `--delay-ms 2.5` (float); `--delay-ms 100000` (over the 60s MAX_DELAY_MS); `--delay-ms -100` (negative); `--delay-ms abc` or `--delay-ms 3s` (non-numeric/suffixed), so Number.isInteger(value) fails or the range check trips.

Common situations: Users expressing seconds instead of milliseconds ('5s' instead of 5000); assuming the cap is higher and setting 120000; NaN produced by a CLI framework when a flag value is missing; floats copy-pasted from config.

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/869e88dce2192c4c. Report an issue: GitHub.