jackwener/OpenCLI · error · ArgumentError
--index must be between 1 and ${max} for this job
Error message
--index must be between 1 and ${max} for this job What it means
This is the range branch of parseImageIndices: the --index value is a valid integer but falls outside 1..max, where max equals the job's batch size (default 4). It throws "--index must be between 1 and ${max} for this job". The bound is dynamic per job, so a smaller batch lowers the allowed maximum.
Source
Thrown at clis/midjourney/utils.js:86
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',
);
}
export function parseImageIndices(value, batchSize = 4) {
const max = Number.isInteger(batchSize) && batchSize > 0 ? batchSize : 4;
const raw = String(value ?? 'all').trim().toLowerCase();
if (!raw || raw === 'all') return Array.from({ length: max }, (_, index) => index);
if (!/^\d+$/.test(raw)) {
throw new ArgumentError(`--index must be "all" or an integer from 1 to ${max}`);
}
const userIndex = Number(raw);
if (userIndex < 1 || userIndex > max) {
throw new ArgumentError(`--index must be between 1 and ${max} for this job`);
}
return [userIndex - 1];
}
export function normalizePrompt(value) {
const prompt = String(value ?? '').replace(/\s+/g, ' ').trim();
if (!prompt) {
throw new ArgumentError(
'prompt cannot be empty',
'Example: opencli midjourney generate "a blue ceramic teapot --ar 1:1"',
);
}
return prompt;
}
export function promptFromFullCommand(value) {
return String(value ?? '')
.replace(/^\s*\/?imagine\s*(?:prompt\s*:)?\s*/i, '')View on GitHub (pinned to 49907e53dc)
Solutions
- Use an index between 1 and the batch size shown in the error message (e.g. 1-4 for a standard job)
- Use --index all if you want every image in the job
- Verify how many images the job actually produced before selecting an index
- If the target image should exist, re-check the job status first — the batch may be smaller than expected
Example fix
// before opencli midjourney upscale <job-id> --index 0 // after opencli midjourney upscale <job-id> --index 1
Defensive patterns
Strategy: validation
Validate before calling
function clampIndex(value, batchSize = 4) {
const n = Number(value);
if (!Number.isInteger(n) || n < 1 || n > batchSize) {
throw new Error(`index must be between 1 and ${batchSize}`);
}
return n;
}
const index = clampIndex(opts.index, job.batchSize ?? 4); Type guard
function isIndexInRange(v, max) {
return Number.isInteger(v) && v >= 1 && v <= max;
} Try / catch
try {
await upscale(jobId, { index });
} catch (err) {
if (err.name === 'ArgumentError' && /between 1 and/.test(err.message)) {
console.error(`${err.message} — check the job's actual image count first`);
process.exitCode = 2;
} else throw err;
} Prevention
- Use 1-based indexing (1-4 for a standard 4-image job)
- Check job status/image count before choosing an index
- Use --index all to avoid range mistakes entirely
- Don't reuse indices across jobs with different batch sizes
When it happens
Trigger: Passing --index 0 (0-based habit), or --index 5+ when the job produced a 4-image batch, or any index larger than the actual number of images the job generated (e.g. a job that produced fewer images).
Common situations: Users forgetting Midjourney indices are 1-based, targeting an image that doesn't exist because the generation failed partway or returned fewer images, or reusing an index from a job with a different batch size.
Related errors
- ${label} must be between ${min} and ${max}, got ${parsed}
- ${label} must be <= ${max}
- --${name} must be between ${min} and ${max}, got ${parsed}
- flomo memos --${name} must be between 1 and ${max}
- limit must be an integer between 1 and ${max}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/47860c93d0edcd24.
Report an issue: GitHub.