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

  1. Provide a non-empty string for the labeled parameter
  2. Trim/validate input before calling the command
  3. Prompt the user again when input is blank
  4. 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

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


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