jackwener/OpenCLI · error · ArgumentError

${commandName} prompt cannot be empty

Error message

${commandName} prompt cannot be empty

What it means

requireNonEmptyPrompt normalizes the prompt argument with String(prompt ?? '').trim() and throws ArgumentError when nothing remains. This is a guard so chatgpt commands never send an empty prompt to the page. The commandName is interpolated so the message names the specific subcommand that failed.

Source

Thrown at clis/chatgpt/utils.js:162

        }
        return null;
      };

      findComposer.toString = () => 'findComposer';
    `;
}

export function normalizeBooleanFlag(value, fallback = false) {
    if (typeof value === 'boolean') return value;
    if (value == null || value === '') return fallback;
    const normalized = String(value).trim().toLowerCase();
    return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on';
}

export function requireNonEmptyPrompt(prompt, commandName) {
    const text = String(prompt ?? '').trim();
    if (!text) {
        throw new ArgumentError(
            `${commandName} prompt cannot be empty`,
            `Example: opencli ${commandName} "hello"`,
        );
    }
    return text;
}

export function requirePositiveInt(value, flagLabel, hint) {
    if (!Number.isInteger(value) || value < 1) {
        throw new ArgumentError(`${flagLabel} must be a positive integer`, hint);
    }
    return value;
}

export function requireNonNegativeInt(value, flagLabel, hint) {
    if (!Number.isInteger(value) || value < 0) {
        throw new ArgumentError(`${flagLabel} must be a non-negative integer`, hint);
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty prompt string as the positional argument, e.g. opencli chatgpt prompt "hello"
  2. Check the variable you interpolate actually has content before invoking (echo it)
  3. Quote the prompt so the shell does not drop it
  4. Handle the ArgumentError in your wrapper and print the usage hint it carries

Example fix

// before
opencli chatgpt prompt $MSG   // MSG unset -> empty prompt
// after
opencli chatgpt prompt "${MSG:-hello}"
Defensive patterns

Strategy: validation

Validate before calling

const text = String(prompt ?? '').trim();
if (!text) throw new Error('prompt is required');

Type guard

function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }

Try / catch

try { await prompt(text); } catch (e) { if (e instanceof ArgumentError) { console.error(e.message, e.hint); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Calling a chatgpt command (e.g. opencli chatgpt prompt) with no positional argument, with an empty string, or with a value that is only whitespace; also with null/undefined prompt.

Common situations: Scripting with shell variables that expand to empty (unset OPENAI_PROMPT var), quoting mistakes so the arg is swallowed by the shell, or piping empty stdin.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/b85de8611b3113b1. Report an issue: GitHub.