{"record":{"id":"1d44c0427367d0d5","repo":"jackwener/OpenCLI","slug":"repeat-in-the-prompt-must-be-a-positive-integer","errorCode":null,"errorMessage":"--repeat in the prompt must be a positive integer","messagePattern":"--repeat in the prompt must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/capabilities.js","lineNumber":239,"sourceCode":"  }\n  const quality = promptParamValue(prompt, ['q', 'quality']);\n  if (quality && ['v8.1', 'v8.2'].includes(selectedModel)) {\n    throw new ArgumentError(`--quality is not supported by ${selectedModel}`);\n  }\n  if (quality) {\n    const normalizedQuality = Number(quality);\n    if (![0.25, 0.5, 1].includes(normalizedQuality)) {\n      throw new ArgumentError('--quality must be 0.25, 0.5, or 1 for supported legacy models');\n    }\n  }\n\n  const rawRepeat = promptParamValue(prompt, ['r', 'repeat']);\n  const structuredRepeat = args.repeat == null || args.repeat === '' ? null : Number(args.repeat);\n  if (structuredRepeat != null && (!Number.isInteger(structuredRepeat) || structuredRepeat < 1)) {\n    throw new ArgumentError('--repeat must be a positive integer');\n  }\n  if (rawRepeat != null && (!/^\\d+$/.test(rawRepeat) || Number(rawRepeat) < 1)) {\n    throw new ArgumentError('--repeat in the prompt must be a positive integer');\n  }\n  if (structuredRepeat != null && rawRepeat != null && structuredRepeat !== Number(rawRepeat)) {\n    throw new ArgumentError(`--repeat conflicts with the prompt (${structuredRepeat} vs ${rawRepeat})`);\n  }\n  const repeat = structuredRepeat ?? (rawRepeat == null ? 1 : Number(rawRepeat));\n  if (repeat > capabilities.repeatLimit) {\n    throw new ArgumentError(`${capabilities.plan || 'current'} plan allows at most ${capabilities.repeatLimit} repeat/permutation jobs`);\n  }\n\n  let perJobMinutes = hasOmniReference || promptHasFlag(prompt, ['oref'])\n    ? GPU_COST_MINUTES.omni\n    : resolution === 'hd'\n      ? GPU_COST_MINUTES.imageHd\n      : GPU_COST_MINUTES.imageSd;\n  if (promptHasFlag(prompt, ['draft'])) perJobMinutes /= 2;\n  // The current web service charged a full SD batch for a live V6 --q 0.5\n  // job. Keep the cost guard conservative instead of applying historical\n  // quality discounts that are no longer reflected in account credits.","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/capabilities.js#L221-L257","documentation":"resolveGenerationPlan validates the --repeat value found inside the Midjourney prompt text (flags like `--r 4` or `--repeat 4`). This error is thrown when that in-prompt value is not a string of digits, or is 0/negative. The CLI requires repeat to be a positive integer because it multiplies GPU job count and cost.","triggerScenarios":"Calling generate/plan with a prompt containing an invalid in-prompt repeat flag, e.g. prompt 'imagine a cat --r abc', '--r 0', '--repeat -2', '--repeat 2.5', or '--r' with no/empty value. Equivalent to a malformed args.repeat but for the prompt-embedded form.","commonSituations":"Typo in the flag value, copy-pasting examples with fractional repeats, shell quoting swallowing part of the value ('--r ' + empty var), or assuming repeat can be 0 to 'disable' repetition.","solutions":["Change the in-prompt flag to a positive integer, e.g. '... --r 4' (or '--repeat 4').","Remove the --r/--repeat flag from the prompt text entirely and pass it via the structured args.repeat option instead.","If repeat was meant to be 0/omitted, delete the flag; the default repeat is 1.","Trim/inspect the final prompt string before calling the API to ensure no empty or malformed flag values remain."],"exampleFix":"// before\nawait midjourney.generate({ prompt: 'a cat --r 0' });\n// after\nawait midjourney.generate({ prompt: 'a cat', repeat: 4 });","handlingStrategy":"validation","validationCode":"function validPromptRepeat(prompt) {\n  const m = /(?:^|\\s)--(?:r|repeat)(?:[= ]([^\\s]+))?/.exec(prompt);\n  if (!m) return true;\n  const v = m[1];\n  return v != null && /^\\d+$/.test(v) && Number(v) >= 1;\n}\nif (!validPromptRepeat(prompt)) throw new Error('fix --r/--repeat in prompt to a positive integer');","typeGuard":"function isPositiveInt(v) {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1;\n}","tryCatchPattern":"try {\n  await midjourney.generate({ prompt });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('--repeat in the prompt')) {\n    prompt = prompt.replace(/\\s*--(?:r|repeat)(?:[= ]\\S+)?/, '');\n    return midjourney.generate({ prompt, repeat: 1 });\n  }\n  throw err;\n}","preventionTips":["Pass repeat via structured args.repeat instead of embedding flags in prompt text.","Sanitize prompt strings (strip CLI-style flags) before sending them to the API.","Use isPositiveInt on any repeat value before submitting.","Never use 0 or negative numbers to mean 'no repeat' — omit the flag instead."],"tags":["cli","validation","argument-error","repeat"],"backgroundTag":"invalid-parameter-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}