jackwener/OpenCLI · error · ArgumentError
--output cannot be empty
Error message
--output cannot be empty
What it means
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.
Source
Thrown at clis/midjourney/utils.js:264
}
export function isoOrNull(value) {
if (value == null || value === '') return null;
const date = new Date(value);
return Number.isFinite(date.getTime()) ? date.toISOString() : null;
}
export function jobUrl(jobId, index = 0) {
return `${MIDJOURNEY_URL}/jobs/${jobId}?index=${index}`;
}
export function originalImageUrl(jobId, index) {
return `${MIDJOURNEY_CDN}/${jobId}/0_${index}.png`;
}
export function resolveOutputDir(value) {
const raw = String(value || '~/Pictures/Midjourney').trim();
if (!raw) throw new ArgumentError('--output cannot be empty');
const expanded = raw === '~' ? os.homedir() : raw.startsWith('~/') ? path.join(os.homedir(), raw.slice(2)) : raw;
return path.resolve(expanded);
}
function errorMessage(error) {
return error instanceof Error ? error.message : String(error);
}
async function midjourneyJson(page, endpoint, options = {}) {
try {
return await page.fetchJson(endpoint, {
...options,
headers: { ...CSRF_HEADERS, ...(options.headers || {}) },
});
} catch (error) {
const message = errorMessage(error);
if (/HTTP\s+(401|403)|unauthori[sz]ed|login|sign in/i.test(message)) {
throw new AuthRequiredError(MIDJOURNEY_DOMAIN, 'Log into Midjourney in Chrome, then retry.');View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
spawn('midjourney', ['fetch', '--output=' + userOutput]); // userOutput may be ''
// after
const args = ['fetch'];
if (userOutput && userOutput.trim()) args.push('--output=' + userOutput);
spawn('midjourney', args); Defensive patterns
Strategy: validation
Validate before calling
if (typeof output !== 'string' || !output.trim()) throw new TypeError('--output must be a non-empty string'); Type guard
function isValidOutputDir(value) {
return typeof value === 'string' && value.trim().length > 0;
} Try / catch
try {
const dir = resolveOutputDir(cliFlags.output);
} catch (err) {
if (err instanceof ArgumentError && /--output cannot be empty/.test(err.message)) {
console.warn('--output empty, using default ~/Pictures/Midjourney');
var dir = resolveOutputDir(undefined);
} else throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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/20ed2a3e90a3cbfa.
Report an issue: GitHub.