{"record":{"id":"a657ccff34485a32","repo":"jackwener/OpenCLI","slug":"prompt-cannot-be-empty","errorCode":null,"errorMessage":"prompt cannot be empty","messagePattern":"prompt cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":94,"sourceCode":"\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}\n\nexport function promptFromFullCommand(value) {\n  return String(value ?? '')\n    .replace(/^\\s*\\/?imagine\\s*(?:prompt\\s*:)?\\s*/i, '')\n    .replace(/\\s+/g, ' ')\n    .trim();\n}\n\nexport function promptCore(value) {\n  return promptFromFullCommand(value)\n    .split(/\\s+--[a-z][a-z0-9-]*/i, 1)[0]\n    .replace(/^(?:https?:\\/\\/\\S+\\s+)+/i, '')","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L76-L112","documentation":"normalizePrompt collapses whitespace and trims the prompt for generate-like commands, then throws ArgumentError \"prompt cannot be empty\" if nothing remains. It prevents sending empty generation requests to the Midjourney API.","triggerScenarios":"Calling generate/interrogate-style commands with an omitted --prompt, an empty string \"\", a prompt that is only whitespace (spaces, tabs, newlines), or a shell variable that expanded to nothing.","commonSituations":"Missing quoted argument in scripts so an empty variable is passed, prompts built from config files where the key is unset, or a prompt consisting solely of whitespace after copy-paste of invisible characters stripping to empty.","solutions":["Pass a non-empty quoted prompt text to the command","If the prompt comes from a variable/config, print it first to confirm it is non-empty","Quote the prompt in shell to avoid word-splitting dropping it entirely","Combine flag-based prompts correctly (don't pass the text under the wrong flag)"],"exampleFix":"// before\nPROMPT=\"\"\nopencli midjourney generate \"$PROMPT\"\n// after\nPROMPT=\"a blue ceramic teapot --ar 1:1\"\nopencli midjourney generate \"$PROMPT\"","handlingStrategy":"validation","validationCode":"function requirePrompt(value) {\n  const p = String(value ?? '').replace(/\\s+/g, ' ').trim();\n  if (!p) throw new Error('prompt cannot be empty');\n  return p;\n}\nconst prompt = requirePrompt(process.env.MJ_PROMPT);","typeGuard":"function hasPrompt(v) {\n  return typeof v === 'string' && v.replace(/\\s+/g, ' ').trim().length > 0;\n}","tryCatchPattern":"try {\n  await generate({ prompt });\n} catch (err) {\n  if (err.name === 'ArgumentError' && /prompt cannot be empty/.test(err.message)) {\n    console.error('Provide a non-empty prompt, e.g. \"a blue ceramic teapot --ar 1:1\"');\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Always quote prompt arguments in shell","Validate prompt variables are non-empty before invoking the CLI","Trim/normalize prompts built from config or user input yourself","Fail fast in scripts: check [ -n \"$PROMPT\" ] before calling the command"],"tags":["cli","argument-validation","empty-input","midjourney"],"backgroundTag":"empty-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}