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
- Pass a non-empty prompt string with actual content
- Check the variable/file feeding the prompt is populated
- 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
- Check prompt source (file/arg/env) is populated before calling
- Trim inputs early and fail with your own message
- Avoid interpolating possibly-empty shell variables unvalidated
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
- <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/ffdc6f385b65a209.
Report an issue: GitHub.