jackwener/OpenCLI · warning · ArgumentError
${label} cannot be empty
Error message
${label} cannot be empty What it means
requireText normalizes a string parameter (collapsing whitespace, trimming) and throws ArgumentError when the result is empty. It guards xianyu commands that need non-empty text (e.g. message content, peer identifiers).
Source
Thrown at clis/xianyu/im.js:37
}
export function normalizeRank(value) {
const raw = String(value ?? '').trim();
if (!raw) return 0;
if (!/^\d+$/.test(raw)) {
throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');
}
const n = Number(raw);
if (!Number.isSafeInteger(n) || n < 1) {
throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');
}
return n;
}
export function requireText(value, label) {
const text = String(value ?? '').replace(/\s+/g, ' ').trim();
if (!text) {
throw new ArgumentError(`${label} cannot be empty`);
}
return text;
}
export function requireEvaluateObject(payload, label) {
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError(`Xianyu ${label} returned malformed browser payload`);
}
return payload;
}
export function requireClickResult(payload, label) {
const result = requireEvaluateObject(payload, label);
if (result.ok !== true) {
throw new CommandExecutionError(`Xianyu ${label} failed: ${result.reason || 'unknown-reason'}`);
}
return result;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Provide a non-empty string for the labeled parameter
- Trim/validate input before calling the command
- Prompt the user again when input is blank
- Add a guard: if (!text?.trim()) skip or error early in your code
Example fix
// before
await xianyuSend({ text: userInput }); // throws when blank
// after
const text = (userInput ?? '').trim();
if (!text) throw new Error('message text required');
await xianyuSend({ text }); Defensive patterns
Strategy: validation
Validate before calling
const text = String(value ?? '').replace(/\s+/g, ' ').trim();
if (!text) throw new Error(`${label} cannot be empty`); Type guard
function isNonEmptyText(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await xianyuSend({ text });
} catch (e) {
if (e?.name === 'ArgumentError' && /cannot be empty/.test(e.message)) {
throw new Error('please provide a message body');
}
throw e;
} Prevention
- Trim and check input before calling
- Never pass null/undefined where text is required
- Re-prompt users for blank message bodies
When it happens
Trigger: Calling a xianyu command with text='' , text=' ', text=null, or text='\n\t' — anything that trims to the empty string.
Common situations: Empty message body from an upstream template; whitespace-only user input; null passed instead of a default; placeholder never substituted.
Related errors
- xianyu ${label} must be an integer between 1 and ${maxValue}
- xianyu rank must be a positive integer from xianyu inbox
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/b6e84ad018e2fdd6.
Report an issue: GitHub.