{"record":{"id":"fd7a1a2bef538421","repo":"jackwener/OpenCLI","slug":"index-must-be-all-or-an-integer-from-1-to-ma","errorCode":null,"errorMessage":"--index must be \"all\" or an integer from 1 to ${max}","messagePattern":"--index must be \"all\" or an integer from 1 to (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":82,"sourceCode":"  try {\n    const parsed = new URL(raw);\n    const match = parsed.pathname.match(/^\\/jobs\\/([0-9a-f-]{36})\\/?$/i);\n    if (parsed.protocol === 'https:' && parsed.hostname === MIDJOURNEY_DOMAIN && match && UUID_RE.test(match[1])) {\n      return match[1].toLowerCase();\n    }\n  } catch {}\n  throw new ArgumentError(\n    'job-id must be a Midjourney UUID or https://www.midjourney.com/jobs/<uuid> URL',\n    'Example: opencli midjourney status d5664250-5f1f-4cd0-9637-2ce0153dd30a',\n  );\n}\n\nexport function parseImageIndices(value, batchSize = 4) {\n  const max = Number.isInteger(batchSize) && batchSize > 0 ? batchSize : 4;\n  const raw = String(value ?? 'all').trim().toLowerCase();\n  if (!raw || raw === 'all') return Array.from({ length: max }, (_, index) => index);\n  if (!/^\\d+$/.test(raw)) {\n    throw new ArgumentError(`--index must be \"all\" or an integer from 1 to ${max}`);\n  }\n  const userIndex = Number(raw);\n  if (userIndex < 1 || userIndex > max) {\n    throw new ArgumentError(`--index must be between 1 and ${max} for this job`);\n  }\n  return [userIndex - 1];\n}\n\nexport function normalizePrompt(value) {\n  const prompt = String(value ?? '').replace(/\\s+/g, ' ').trim();\n  if (!prompt) {\n    throw new ArgumentError(\n      'prompt cannot be empty',\n      'Example: opencli midjourney generate \"a blue ceramic teapot --ar 1:1\"',\n    );\n  }\n  return prompt;\n}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L64-L100","documentation":"parseImageIndices converts the --index option (e.g. for upscaling or varying a batch) into zero-based image indices. After handling \"all\", any value that is not purely digits (1-N) throws \"--index must be \\\"all\\\" or an integer from 1 to ${max}\". This is the format check; the range check produces a different message.","triggerScenarios":"Passing --index values like \"1,2\" (comma-separated), \"1-4\" (ranges), \"first\", \"0\", or any non-numeric string. Empty string is treated as \"all\" and does NOT trigger this. Note \"0\" passes the regex but fails the range check, producing error 2628 instead.","commonSituations":"Users writing comma lists or ranges as they would in other tools, quoting issues in shell scripts, or using 0-based indexing out of habit when this CLI is 1-based.","solutions":["Pass a single integer between 1 and the job's batch size (default 4), or the literal word \"all\"","Replace comma lists/ranges with a single index and run the command once per image","Verify you are using 1-based indexing, not 0-based","Check the job's batch size to know the valid maximum"],"exampleFix":"// before\nopencli midjourney upscale <job-id> --index 1,3\n// after\nopencli midjourney upscale <job-id> --index 1","handlingStrategy":"validation","validationCode":"function parseIndexInput(value, batchSize = 4) {\n  const raw = String(value ?? 'all').trim().toLowerCase();\n  if (!raw || raw === 'all') return 'all';\n  if (!/^\\d+$/.test(raw)) throw new Error(`--index must be \"all\" or a single integer`);\n  const n = Number(raw);\n  if (n < 1 || n > batchSize) throw new Error(`--index must be between 1 and ${batchSize}`);\n  return n;\n}","typeGuard":"function isIndexFormat(v) {\n  const raw = String(v ?? 'all').trim().toLowerCase();\n  return raw === 'all' || /^\\d+$/.test(raw);\n}","tryCatchPattern":"try {\n  await upscale(jobId, { index: parseIndexInput(opts.index) });\n} catch (err) {\n  if (err.name === 'ArgumentError' && /--index/.test(err.message)) {\n    console.error(err.message);\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Remember: one integer or the word \"all\" — no comma lists or ranges","Indices are 1-based, not 0-based","Omit the flag entirely when you want all images","Escape/quote values in shell so \"all\" is not misparsed"],"tags":["cli","argument-validation","midjourney"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}