jackwener/OpenCLI · error · ArgumentError
${label} accepts exactly one reference
Error message
${label} accepts exactly one reference What it means
When the multiple option is disabled, the reference parser enforces that exactly one reference was supplied. If the resolved list contains more than one item, this ArgumentError is thrown, because the command consuming the reference only supports a single input.
Source
Thrown at clis/midjourney/utils.js:878
}
export function parseReferenceArgument(value, label, { multiple = true, allowStyleCode = false } = {}) {
if (value == null || value === '') return [];
let items;
const raw = String(value).trim();
if (raw.startsWith('[')) {
try {
items = JSON.parse(raw);
} catch (error) {
throw new ArgumentError(`${label} must be a path/URL or a JSON array: ${errorMessage(error)}`);
}
} else {
items = [raw];
}
if (!Array.isArray(items) || items.length === 0 || items.some((item) => typeof item !== 'string' || !item.trim())) {
throw new ArgumentError(`${label} must contain one or more non-empty strings`);
}
if (!multiple && items.length !== 1) throw new ArgumentError(`${label} accepts exactly one reference`);
return items.map((item) => item.trim()).map((item) => {
if (allowStyleCode && /^\d+$/.test(item)) return { kind: 'styleCode', value: item };
if (/^https:\/\//i.test(item)) {
try {
const parsed = new URL(item);
const match = parsed.hostname === MIDJOURNEY_DOMAIN
? parsed.pathname.match(/^\/jobs\/([0-9a-f-]{36})\/?$/i)
: null;
if (match && UUID_RE.test(match[1])) {
const index = Number(parsed.searchParams.get('index') || 0);
if (!Number.isInteger(index) || index < 0 || index > 3) {
throw new ArgumentError(`${label} Midjourney job URL index must be 0..3: ${item}`);
}
return { kind: 'url', value: originalImageUrl(match[1].toLowerCase(), index), source: item };
}
} catch (error) {
if (error instanceof ArgumentError) throw error;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass exactly one reference, e.g. --refs './cat.png'
- Enable the multiple option/flag if several references are genuinely supported for that argument
- Split the work into multiple invocations, one reference per call
Example fix
// before
parseReferences('refs', '["a.png","b.png"]', { multiple: false });
// after
parseReferences('refs', '["a.png","b.png"]', { multiple: true });
// or single:
parseReferences('refs', 'a.png', { multiple: false }); Defensive patterns
Strategy: validation
Validate before calling
if (!multiple && parsedItems.length !== 1) {
throw new Error('this argument accepts exactly one reference; pass multiple: true for lists');
} Type guard
const isSingleRef = (v) => typeof v === 'string' || (Array.isArray(v) && v.length === 1);
Try / catch
try {
const refs = parseReferences('refs', raw, { multiple: false });
} catch (e) {
if (String(e.message).includes('accepts exactly one reference')) {
console.error('Pass a single reference or enable multiple mode');
}
throw e;
} Prevention
- Check whether the argument supports multiple references before passing arrays
- Default scripts to one reference per invocation
- Keep separate flag names/paths for single vs batch workflows
When it happens
Trigger: Calling without the multiple flag/option while passing a JSON array with 2+ items (e.g. '["a.png","b.png"]') for a single-reference parameter.
Common situations: Scripts written for multi-reference commands reused on single-reference flags, users assuming flags accept lists by default, or copy-pasted multi-image examples run against a single-image argument.
Related errors
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
- --from and --to must differ; both resolved to ${fromStation.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d33e05abe56f7f3c.
Report an issue: GitHub.