jackwener/OpenCLI · error · ArgumentError

${label} must be <= ${max}

Error message

${label} must be <= ${max}

What it means

normalizePositiveInt validates that a CLI option value (e.g. --timeout, --limit) is a positive integer and does not exceed an upper bound. When the parsed value exceeds the `max` argument, it throws ArgumentError with "${label} must be <= ${max}". This guards API calls against values the Midjourney service would reject.

Source

Thrown at clis/midjourney/utils.js:56

    return payload.data;
  }
  return payload;
}

export function normalizeBoolean(value, fallback = false) {
  if (typeof value === 'boolean') return value;
  if (value == null || value === '') return fallback;
  const normalized = String(value).trim().toLowerCase();
  return ['true', '1', 'yes', 'on'].includes(normalized);
}

export function normalizePositiveInt(value, fallback, max, label) {
  const parsed = value == null || value === '' ? fallback : Number(value);
  if (!Number.isInteger(parsed) || parsed < 1) {
    throw new ArgumentError(`${label} must be a positive integer`);
  }
  if (parsed > max) {
    throw new ArgumentError(`${label} must be <= ${max}`);
  }
  return parsed;
}

export function parseJobId(value) {
  const raw = String(value ?? '').trim();
  if (UUID_RE.test(raw)) return raw.toLowerCase();
  try {
    const parsed = new URL(raw);
    const match = parsed.pathname.match(/^\/jobs\/([0-9a-f-]{36})\/?$/i);
    if (parsed.protocol === 'https:' && parsed.hostname === MIDJOURNEY_DOMAIN && match && UUID_RE.test(match[1])) {
      return match[1].toLowerCase();
    }
  } catch {}
  throw new ArgumentError(
    'job-id must be a Midjourney UUID or https://www.midjourney.com/jobs/<uuid> URL',
    'Example: opencli midjourney status d5664250-5f1f-4cd0-9637-2ce0153dd30a',
  );

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check the specific max shown in the error message and lower the option value to that or below
  2. Run the command's help (opencli midjourney --help) to confirm the accepted range for --timeout/--limit
  3. Fix the value in your config file or script where the oversized default is set
  4. If you genuinely need a higher value, split the work into multiple calls within the allowed range

Example fix

// before
opencli midjourney list --limit 500
// after
opencli midjourney list --limit 100
Defensive patterns

Strategy: validation

Validate before calling

function isValidPositiveInt(value, max) {
  const n = value == null || value === '' ? NaN : Number(value);
  return Number.isInteger(n) && n >= 1 && n <= max;
}
if (!isValidPositiveInt(opts.limit, 100)) throw new Error('--limit must be <= 100');

Type guard

function isPositiveIntWithinMax(v, max) {
  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= max;
}

Try / catch

try {
  runCommand(opts);
} catch (err) {
  if (err.name === 'ArgumentError' && /must be <=/.test(err.message)) {
    console.error(`Invalid option value: ${err.message}`);
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Calling any midjourney subcommand that resolves `timeout` or `limit` options with a value that parses to a valid positive integer but is greater than the configured max for that option (e.g. --limit 1000 when max is 100).

Common situations: Users copying limits from other tools, misremembering the max for a command, script variables containing oversized defaults, or config files with stale values after the CLI tightened its bounds.

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