jackwener/OpenCLI · error · ArgumentError

douyin search 需要 <query> 关键词

Error message

douyin search 需要 <query> 关键词

What it means

The douyin search command requires a query keyword. It reads kwargs.query, trims it, and throws this ArgumentError when the result is empty. Without a keyword there is no search URL to navigate to (https://www.douyin.com/search/<keyword>?type=video), so the command fails fast before touching the browser.

Source

Thrown at clis/douyin/search.js:269

}

cli({
    site: 'douyin',
    name: 'search',
    access: 'read',
    description: '关键词搜索抖音视频',
    domain: 'www.douyin.com',
    strategy: Strategy.COOKIE,
    args: [
        { name: 'query', required: true, positional: true, help: '搜索关键词' },
        { name: 'limit', type: 'int', default: 10, help: `结果数量 (1-${MAX_SEARCH_LIMIT})` },
    ],
    columns: ['rank', 'desc', 'author', 'url', 'plays', 'likes', 'comments', 'shares'],
    func: async (page, kwargs) => {
        const limit = parseSearchLimit(kwargs.limit);
        const keyword = String(kwargs.query ?? '').trim();
        if (!keyword) {
            throw new ArgumentError('douyin search 需要 <query> 关键词');
        }
        await page.goto(`https://www.douyin.com/search/${encodeURIComponent(keyword)}?type=video`);
        let result;
        try {
            result = unwrapEvaluateResult(await page.evaluate(WAIT_AND_EXTRACT_JS(RENDER_TIMEOUT_MS)));
        } catch (error) {
            throw new CommandExecutionError(`Douyin search extraction failed: ${error instanceof Error ? error.message : String(error)}`);
        }
        if (!result || typeof result !== 'object') {
            throw new CommandExecutionError('Douyin search: unexpected evaluator payload shape');
        }
        if (result.state === 'login_wall') {
            throw new AuthRequiredError(
                'www.douyin.com',
                'Douyin search results are blocked behind a login wall — log in at https://www.douyin.com in Chrome first.',
            );
        }
        if (result.state === 'empty') {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide a non-empty query: douyin search --query "cats"
  2. Trim/validate the query in the calling script before invoking the command
  3. Fail early with a clear usage message when the upstream variable is empty

Example fix

// before
const q = process.env.QUERY ?? '';
await douyin.search({ query: q, limit: 10 });
// after
const q = (process.env.QUERY ?? '').trim();
if (!q) throw new Error('QUERY env var is required');
await douyin.search({ query: q, limit: 10 });
Defensive patterns

Strategy: validation

Validate before calling

const query = String(kwargs.query ?? '').trim();
if (!query) {
  throw new Error('usage: douyin search --query <keyword>');
}

Type guard

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

Try / catch

try {
  await douyin.search({ query: rawQuery, limit });
} catch (e) {
  if (e instanceof ArgumentError && /需要 <query> 关键词/.test(e.message)) {
    console.error('A non-empty --query is required');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking search with no --query flag, an empty string (''), or whitespace-only (' ') value — kwargs.query ?? '' .trim() then evaluates falsy.

Common situations: Scripts building the command from variables where the query came from an empty env var or CLI arg; users passing only --limit or filters; template invocations with an unfilled placeholder.

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/2935f726292fbe45. Report an issue: GitHub.