jackwener/OpenCLI · error · ArgumentError

${label} must be one of: ${choices.join(', ')}

Error message

${label} must be one of: ${choices.join(', ')}

What it means

ArgumentError thrown by the `choice` helper in `opencli midjourney history` when the --type or --status flag value is not one of the allowed enumerated values after trimming and lowercasing. The library validates filter inputs against fixed choice lists (TYPE_CHOICES = all/image/video; STATUS_CHOICES = all/queued/running/completed/failed/cancelled) before making any network request, so invalid filters fail fast.

Source

Thrown at clis/midjourney/history.js:18

import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import {
  fetchHistoryPage,
  fetchJobStatuses,
  getMidjourneyAccount,
  isVideoJob,
  jobStatusRow,
  normalizePositiveInt,
  promptFromFullCommand,
} from './utils.js';

const TYPE_CHOICES = ['all', 'image', 'video'];
const STATUS_CHOICES = ['all', 'queued', 'running', 'completed', 'failed', 'cancelled'];

function choice(value, fallback, choices, label) {
  const result = String(value ?? fallback).trim().toLowerCase();
  if (!choices.includes(result)) throw new ArgumentError(`${label} must be one of: ${choices.join(', ')}`);
  return result;
}

cli({
  site: 'midjourney',
  name: 'history',
  access: 'read',
  description: 'List recent Midjourney image, video, and derived jobs with real lifecycle status',
  example: 'opencli midjourney history --limit 10 --type all -f json',
  domain: 'www.midjourney.com',
  strategy: Strategy.COOKIE,
  browser: true,
  siteSession: 'persistent',
  navigateBefore: 'https://www.midjourney.com/imagine',
  args: [
    { name: 'limit', type: 'int', default: 10, help: 'Number of matching jobs (1..100)' },
    { name: 'type', default: 'all', help: 'all, image, or video' },
    { name: 'status', default: 'all', help: 'all, queued, running, completed, failed, or cancelled' },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use exactly one of the listed values: --type all|image|video and --status all|queued|running|completed|failed|cancelled.
  2. Check spelling, especially 'completed' (not 'complete') and 'cancelled' (not 'canceled' on input).
  3. Read the help output (`opencli midjourney history --help`) for the accepted values.
  4. Validate user-supplied filter values in wrapper scripts before invoking the CLI.

Example fix

// before
opencli midjourney history --status complete --type vid
// after
opencli midjourney history --status completed --type video
Defensive patterns

Strategy: validation

Validate before calling

const TYPE_CHOICES = ['all', 'image', 'video'];
const STATUS_CHOICES = ['all', 'queued', 'running', 'completed', 'failed', 'cancelled'];
function assertChoice(label, value, choices) {
  const v = String(value ?? '').trim().toLowerCase();
  if (!choices.includes(v)) throw new Error(`${label} must be one of: ${choices.join(', ')} (got "${value}")`);
  return v;
}
const type = assertChoice('--type', 'video', TYPE_CHOICES);
const status = assertChoice('--status', 'completed', STATUS_CHOICES);

Type guard

function isHistoryType(v) { return ['all','image','video'].includes(v); }
function isHistoryStatus(v) { return ['all','queued','running','completed','failed','cancelled'].includes(v); }

Try / catch

import { ArgumentError } from '@jackwener/opencli/errors';
try {
  await opencli.midjourney.history({ type, status });
} catch (e) {
  if (e instanceof ArgumentError && /must be one of/.test(e.message)) {
    console.error(`Bad filter: ${e.message}`); process.exitCode = 2; return;
  }
  throw e;
}

Prevention

When it happens

Trigger: `opencli midjourney history --type image2` or `--type Image` is fine (lowercased) but `--type vid` (not exact) fails; `--status complete` instead of `--status completed`; `--status cancel` instead of `--status cancelled`; passing an empty or non-string value that normalizes outside the lists.

Common situations: Typos or truncated enum values on the command line; scripting the CLI with user input that isn't validated; assuming singular forms ('image' is valid but 'complete'/'cancel' abbreviations of status are not); confusing 'cancelled' (double-l) spelling with US 'canceled'.

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