jackwener/OpenCLI · error · ArgumentError

query is required

Error message

query is required

What it means

requirePrompt normalizes the query argument of `xiaohongshu ask`; after String-coercion and trimming, an empty/absent query throws this ArgumentError. The command needs a non-empty natural-language question to send to 点点, so it fails fast rather than launching a browser session with nothing to ask.

Source

Thrown at clis/xiaohongshu/ask.js:359

            warning: sourceError,
            message_id: msgId,
            conversation_id: conversationId,
          };
        } catch (err) {
          return {
            ok: false,
            error: String(err?.message || err || 'unknown_error'),
            stack: String(err?.stack || '').slice(0, 1500),
            page_url: location.href,
          };
        }
      })()
    `;
}

function requirePrompt(query) {
    const prompt = String(query || '').trim();
    if (!prompt) throw new ArgumentError('query is required');
    return prompt;
}

function mapAskError(raw, timeoutSeconds) {
    const error = compactSingleLine(raw?.error);
    if (error === 'answer_timeout') {
        throw new TimeoutError('xiaohongshu ask', timeoutSeconds, '点点没有在超时时间内返回答案;可以重试或提高 --timeout。');
    }
    if (error === 'send_message_failed') {
        throw new AuthRequiredError(XHS_WEB_HOST, 'Xiaohongshu 点点 did not accept the query. Check login status for www.xiaohongshu.com.');
    }
    throw new CommandExecutionError(
        `xiaohongshu ask failed: ${error || 'unknown error'}`,
        raw?.page_url ? `Page URL: ${raw.page_url}` : undefined,
    );
}

function requireAskPayload(raw) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty quoted query: opencli xiaohongshu ask "how to X"
  2. Check the shell variable holding the question is actually set and non-blank
  3. Quote the argument so leading/trailing spaces or special chars are preserved
  4. In wrapper scripts, validate the prompt before invoking the CLI

Example fix

// before
opencli xiaohongshu ask "$QUERY"   # QUERY is empty
// after
[ -n "$QUERY" ] && opencli xiaohongshu ask "$QUERY"
Defensive patterns

Strategy: validation

Validate before calling

const prompt = String(process.argv[3] ?? '').trim();
if (!prompt) {
  console.error('usage: opencli xiaohongshu ask "<question>"');
  process.exit(2);
}

Type guard

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

Try / catch

try {
  await xiaohongshuAsk({ query });
} catch (e) {
  if (e.name === 'ArgumentError' && e.message === 'query is required') {
    console.error('Provide a non-empty question, e.g. opencli xiaohongshu ask "how to X"');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `opencli xiaohongshu ask` with no positional query, with an empty string '', or with only whitespace like " "; also query values that are null/undefined from a wrapper script.

Common situations: Shell variable expansion yielding an empty value ($Q unset with set -u not enabled); pipes/args mis-ordered so the question never reaches the command; copy-paste losing the quoted argument.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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