jackwener/OpenCLI · error · ArgumentError

--batch-size must be 1, 2, or 4

Error message

--batch-size must be 1, 2, or 4

What it means

For video reruns, estimateAction restricts batchSize to 1, 2, or 4 because GPU cost keys (videoSd1, videoHd2, ...) only exist for those sizes. Any other batchSize (including 0, 3, or non-numbers) throws this ArgumentError.

Source

Thrown at clis/midjourney/capabilities.js:301

  if (Number.isFinite(remainingMinutes) && remainingMinutes - estimatedMinutes < reserve) {
    throw new CommandExecutionError(
      `Midjourney budget guard would leave ${Number((remainingMinutes - estimatedMinutes).toFixed(2))} minutes, below the ${reserve}-minute reserve`,
    );
  }
  return { maxMinutes: max, reserveMinutes: reserve, remainingMinutes };
}

export function estimateAction(
  operation,
  { videoResolution = 'sd', batchSize = 1, sourceIsVideo = false, sourceUsesOmni = false } = {},
) {
  if (!ACTION_CHOICES.includes(operation)) {
    throw new ArgumentError(`operation must be one of: ${ACTION_CHOICES.join(', ')}`);
  }
  if (operation === 'open-editor' || operation === 'cancel') return 0;
  if (operation === 'rerun' && sourceIsVideo) {
    if (!['sd', 'hd'].includes(videoResolution)) throw new ArgumentError('--video-resolution must be sd or hd');
    if (![1, 2, 4].includes(batchSize)) throw new ArgumentError('--batch-size must be 1, 2, or 4');
    return GPU_COST_MINUTES[`video${videoResolution === 'hd' ? 'Hd' : 'Sd'}${batchSize}`];
  }
  if (sourceUsesOmni && ['rerun', 'vary-subtle', 'vary-strong'].includes(operation)) {
    return GPU_COST_MINUTES.omni;
  }
  if (Object.prototype.hasOwnProperty.call(ACTION_COSTS, operation)) return ACTION_COSTS[operation];
  if (['animate-low', 'animate-high', 'loop-low', 'loop-high', 'extend-low', 'extend-high'].includes(operation)) {
    if (!['sd', 'hd'].includes(videoResolution)) throw new ArgumentError('--video-resolution must be sd or hd');
    if (![1, 2, 4].includes(batchSize)) throw new ArgumentError('--batch-size must be 1, 2, or 4');
    return GPU_COST_MINUTES[`video${videoResolution === 'hd' ? 'Hd' : 'Sd'}${batchSize}`];
  }
  throw new ArgumentError(`No cost model is defined for action "${operation}"`);
}

export function assertActionPlan(account, operation, { videoResolution = 'sd' } = {}) {
  const capabilities = planCapabilities(account);
  if (videoResolution === 'hd' && !capabilities.canHdVideo
    && ['animate-low', 'animate-high', 'loop-low', 'loop-high', 'extend-low', 'extend-high'].includes(operation)) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use batchSize of exactly 1, 2, or 4 (a number, not a string)
  2. Coerce and validate: Number(kwargs.batchSize) and check [1,2,4].includes(n) before the call
  3. Update the CLI flag help text so users know the allowed set
  4. Snap invalid values to the nearest allowed size at the CLI boundary if snapping is acceptable

Example fix

// before
estimateAction('rerun', { sourceIsVideo: true, batchSize: '2' });
// after
const n = Number(opts.batchSize);
if (![1, 2, 4].includes(n)) throw new Error('--batch-size must be 1, 2, or 4');
estimateAction('rerun', { sourceIsVideo: true, batchSize: n });
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(opts.batchSize ?? 1);
if (!Number.isInteger(n) || ![1, 2, 4].includes(n)) {
  throw new Error(`--batch-size must be 1, 2, or 4, got ${opts.batchSize}`);
}
const minutes = estimateAction('rerun', { sourceIsVideo: true, batchSize: n, ...opts });

Type guard

function isValidBatchSize(n) {
  return typeof n === 'number' && Number.isInteger(n) && [1, 2, 4].includes(n);
}

Try / catch

try {
  const minutes = estimateAction('rerun', { sourceIsVideo: true, batchSize, videoResolution });
} catch (err) {
  if (err instanceof ArgumentError && err.message.includes('--batch-size')) {
    console.error('Allowed batch sizes: 1, 2, 4');
  } else throw err;
}

Prevention

When it happens

Trigger: estimateAction('rerun', { sourceIsVideo: true, batchSize: 3 }) or batchSize as a string '2' from an uncoerced CLI flag.

Common situations: Users passing --batch-size 3 (not offered by Midjourney); reading batch size from JSON config where it is a string; arithmetic producing fractional batches.

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/6f3f591f240d3574. Report an issue: GitHub.