jackwener/OpenCLI · error · ArgumentError
--repeat must be a positive integer
Error message
--repeat must be a positive integer
What it means
resolveGenerationPlan() validates the repeat count for Midjourney generation from two places: the structured args (--repeat CLI flag) and the raw prompt parameter (r/repeat). It throws this ArgumentError when the structured --repeat value is present but is not an integer >= 1 — e.g. 0, negative numbers, or non-integer values like '2.5' or 'abc'.
Source
Thrown at clis/midjourney/capabilities.js:236
if (promptHasFlag(prompt, ['video', 'loop'])
|| promptParamValue(prompt, ['video', 'bs', 'motion', 'end'])) {
throw new ArgumentError('Video parameters are not accepted by generate; create an image first, then use `midjourney action`');
}
const quality = promptParamValue(prompt, ['q', 'quality']);
if (quality && ['v8.1', 'v8.2'].includes(selectedModel)) {
throw new ArgumentError(`--quality is not supported by ${selectedModel}`);
}
if (quality) {
const normalizedQuality = Number(quality);
if (![0.25, 0.5, 1].includes(normalizedQuality)) {
throw new ArgumentError('--quality must be 0.25, 0.5, or 1 for supported legacy models');
}
}
const rawRepeat = promptParamValue(prompt, ['r', 'repeat']);
const structuredRepeat = args.repeat == null || args.repeat === '' ? null : Number(args.repeat);
if (structuredRepeat != null && (!Number.isInteger(structuredRepeat) || structuredRepeat < 1)) {
throw new ArgumentError('--repeat must be a positive integer');
}
if (rawRepeat != null && (!/^\d+$/.test(rawRepeat) || Number(rawRepeat) < 1)) {
throw new ArgumentError('--repeat in the prompt must be a positive integer');
}
if (structuredRepeat != null && rawRepeat != null && structuredRepeat !== Number(rawRepeat)) {
throw new ArgumentError(`--repeat conflicts with the prompt (${structuredRepeat} vs ${rawRepeat})`);
}
const repeat = structuredRepeat ?? (rawRepeat == null ? 1 : Number(rawRepeat));
if (repeat > capabilities.repeatLimit) {
throw new ArgumentError(`${capabilities.plan || 'current'} plan allows at most ${capabilities.repeatLimit} repeat/permutation jobs`);
}
let perJobMinutes = hasOmniReference || promptHasFlag(prompt, ['oref'])
? GPU_COST_MINUTES.omni
: resolution === 'hd'
? GPU_COST_MINUTES.imageHd
: GPU_COST_MINUTES.imageSd;
if (promptHasFlag(prompt, ['draft'])) perJobMinutes /= 2;View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer: --repeat 4 instead of 0, -1, or a fraction.
- If the value comes from a variable/script, default and validate it before invoking, e.g. REPEAT=${REPEAT:-1}.
- Put the repeat in the prompt as `--r 4` instead if the structured flag is problematic, keeping values consistent.
- Remove the --repeat flag entirely to use the default count.
Example fix
// before node mj.js plan --prompt "sunset --r 2" --repeat 0 // after node mj.js plan --prompt "sunset --r 2" --repeat 2
Defensive patterns
Strategy: validation
Validate before calling
const repeat = Number(process.env.REPEAT ?? 1);
if (!Number.isInteger(repeat) || repeat < 1) {
throw new Error(`REPEAT must be a positive integer, got: ${process.env.REPEAT}`);
}
// then pass --repeat ${repeat} Type guard
function isValidRepeat(v) {
const n = Number(v);
return v != null && v !== '' && Number.isInteger(n) && n >= 1;
} Try / catch
try {
const plan = await midjourney.plan({ prompt, repeat: repeatArg });
} catch (err) {
if (err instanceof ArgumentError && /--repeat must be a positive integer/.test(err.message)) {
repeatArg = 1; // fall back to default and retry
} else throw err;
} Prevention
- Validate repeat values with Number.isInteger(v) && v >= 1 before calling the API.
- Default unset variables in shell scripts: REPEAT=${REPEAT:-1}.
- If specifying repeat in both the prompt (--r N) and the flag, keep the values identical to avoid the conflict error.
- Avoid fractional or zero counts; repeat is a count of generations, not an index.
When it happens
Trigger: Calling plan()/generation with args.repeat set to something that Number()-coerces to a non-integer or a value < 1 — e.g. --repeat 0, --repeat -2, --repeat 2.5, --repeat abc. (Empty string is treated as unset and skipped.)
Common situations: Shell scripts templating --repeat with an unset variable defaulting to 0; users confusing 0-indexed counts; passing fractional values copied from docs; typo like --repeat 1.5.
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
- --kind must be one of: ${KINDS.join(', ')}
- Image jobs only support --kind image
- ${label} must be <= ${max}
- job-id must be a Midjourney UUID or https://www.midjourney.c
- --index must be "all" or an integer from 1 to ${max}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6b2ce177eb0339dd.
Report an issue: GitHub.