jackwener/OpenCLI · error · ArgumentError

text must not be empty

Error message

text must not be empty

What it means

ensurePrompt coerces its argument to a string and requires non-whitespace content. The library throws this ArgumentError when the prompt text is empty or whitespace-only, because sending an empty prompt to Trae CN is meaningless.

Source

Thrown at clis/trae-cn/utils.js:103

  const unique = Array.from(new Set(expanded));
  if (unique.length === 0) {
    throw new ArgumentError('--approve-kinds must contain at least one approval kind');
  }
  return unique;
}

export function normalizeApprovalLimit(value, fallback = 1) {
  const limit = value === undefined || value === null ? fallback : Number(value);
  if (!Number.isInteger(limit) || limit < 1 || limit > 20) {
    throw new ArgumentError('--limit must be an integer between 1 and 20');
  }
  return limit;
}

export function ensurePrompt(text) {
  const prompt = typeof text === 'string' ? text : '';
  if (!prompt.trim()) {
    throw new ArgumentError('text must not be empty');
  }
  return prompt;
}

export function normalizeModelLabel(text) {
  return String(text || '').toLowerCase().replace(/[^a-z0-9.]+/g, '');
}

export function listOpenModelItemsScript() {
  return `
    (function() {
      return Array.from(document.querySelectorAll('${TRAE_CN_MODEL_ITEM_SELECTOR}'))
        .map((el, index) => ({
          Index: index,
          Model: String(el.innerText || el.textContent || '').replace(/\\s+/g, ' ').trim()
        }))
        .filter(item => item.Model);
    })()

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty prompt string with actual content
  2. Check the variable/file feeding the prompt is populated
  3. Trim and validate user input before calling the API

Example fix

// before
await sendTraePrompt(page, args.prompt || '');
// after
if (!args.prompt?.trim()) throw new Error('prompt required');
await sendTraePrompt(page, args.prompt);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof text !== 'string' || !text.trim()) throw new Error('prompt text must be a non-empty string');

Type guard

const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try { prompt = ensurePrompt(text); } catch (e) { if (/must not be empty/.test(e.message)) { console.error('Provide a non-empty prompt via --text or file'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: sendTraePrompt(page, '') or a prompt built from an empty template variable, a failed file read, or trimming that removed all content.

Common situations: Scripts passing unquoted empty shell variables, or prompts read from files that exist but are blank.

Related errors


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