{"record":{"id":"20ed2a3e90a3cbfa","repo":"jackwener/OpenCLI","slug":"output-cannot-be-empty","errorCode":null,"errorMessage":"--output cannot be empty","messagePattern":"--output cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":264,"sourceCode":"}\n\nexport function isoOrNull(value) {\n  if (value == null || value === '') return null;\n  const date = new Date(value);\n  return Number.isFinite(date.getTime()) ? date.toISOString() : null;\n}\n\nexport function jobUrl(jobId, index = 0) {\n  return `${MIDJOURNEY_URL}/jobs/${jobId}?index=${index}`;\n}\n\nexport function originalImageUrl(jobId, index) {\n  return `${MIDJOURNEY_CDN}/${jobId}/0_${index}.png`;\n}\n\nexport function resolveOutputDir(value) {\n  const raw = String(value || '~/Pictures/Midjourney').trim();\n  if (!raw) throw new ArgumentError('--output cannot be empty');\n  const expanded = raw === '~' ? os.homedir() : raw.startsWith('~/') ? path.join(os.homedir(), raw.slice(2)) : raw;\n  return path.resolve(expanded);\n}\n\nfunction errorMessage(error) {\n  return error instanceof Error ? error.message : String(error);\n}\n\nasync function midjourneyJson(page, endpoint, options = {}) {\n  try {\n    return await page.fetchJson(endpoint, {\n      ...options,\n      headers: { ...CSRF_HEADERS, ...(options.headers || {}) },\n    });\n  } catch (error) {\n    const message = errorMessage(error);\n    if (/HTTP\\s+(401|403)|unauthori[sz]ed|login|sign in/i.test(message)) {\n      throw new AuthRequiredError(MIDJOURNEY_DOMAIN, 'Log into Midjourney in Chrome, then retry.');","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L246-L282","documentation":"resolveOutputDir throws ArgumentError when the --output value is empty after normalization. Note the default path '~/Pictures/Midjourney' is substituted for falsy values first, so this only fires when the caller passes an explicitly empty/whitespace string that survives coercion — e.g. an empty string produced upstream. It guards against resolving the CWD or an invalid path as the download destination.","triggerScenarios":"resolveOutputDir('') or resolveOutputDir('   ') where String(value || default) — e.g. the caller pre-processed the value so the default substitution was bypassed and raw trims to empty. outputDir calls this with user-supplied --output input.","commonSituations":"Shell quoting bugs producing an empty argument (e.g. --output=\"$EMPTY_VAR\"), config files with output: \"\" read by custom code before the CLI default applies, or scripts piping an empty value into the CLI.","solutions":["Pass a non-empty path to --output, or omit the flag entirely to get the ~/Pictures/Midjourney default.","Check shell variables used in --output are actually set before invoking the CLI.","Quote arguments correctly so whitespace-only values do not collapse to nothing."],"exampleFix":"// before\nspawn('midjourney', ['fetch', '--output=' + userOutput]); // userOutput may be ''\n// after\nconst args = ['fetch'];\nif (userOutput && userOutput.trim()) args.push('--output=' + userOutput);\nspawn('midjourney', args);","handlingStrategy":"validation","validationCode":"if (typeof output !== 'string' || !output.trim()) throw new TypeError('--output must be a non-empty string');","typeGuard":"function isValidOutputDir(value) {\n  return typeof value === 'string' && value.trim().length > 0;\n}","tryCatchPattern":"try {\n  const dir = resolveOutputDir(cliFlags.output);\n} catch (err) {\n  if (err instanceof ArgumentError && /--output cannot be empty/.test(err.message)) {\n    console.warn('--output empty, using default ~/Pictures/Midjourney');\n    var dir = resolveOutputDir(undefined);\n  } else throw err;\n}","preventionTips":["Quote shell variables used for --output and check they are non-empty","Omit --output instead of passing an empty value to get the default","Validate config-file output values before passing to the CLI","Add a pre-flight check that trims and tests user-supplied paths"],"tags":["cli","argument-validation","configuration"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}