jackwener/OpenCLI · error · ArgumentError

douyin hashtag search 需要 --keyword <关键词>

Error message

douyin hashtag search 需要 --keyword <关键词>

What it means

The `search` action of `douyin hashtag` requires a non-empty keyword. validateHashtagArgs trims String(kwargs.keyword ?? '') and throws an ArgumentError with a usage example when it is empty. This is a required-argument guard, not an API failure.

Source

Thrown at clis/douyin/hashtag.js:30

    }
    const list = res[field];
    if (list === undefined || list === null) return [];
    if (!Array.isArray(list)) {
        throw new CommandExecutionError(`douyin hashtag ${action}: API returned malformed "${field}"`);
    }
    return list;
}

function validateHashtagArgs(kwargs) {
    const action = kwargs.action;
    const limit = Number(kwargs.limit ?? 10);
    if (!Number.isInteger(limit) || limit < 1) {
        throw new ArgumentError(`--limit must be a positive integer, got ${JSON.stringify(kwargs.limit)}`);
    }
    if (action === 'search') {
        const keyword = String(kwargs.keyword ?? '').trim();
        if (!keyword) {
            throw new ArgumentError('douyin hashtag search 需要 --keyword <关键词>', '示例: opencli douyin hashtag search --keyword 美食');
        }
        return;
    }
    if (action === 'suggest') {
        const cover = String(kwargs.cover ?? '').trim();
        if (!cover) {
            throw new ArgumentError('douyin hashtag suggest 需要 --cover <cover_uri>', 'suggest 基于已上传的视频封面做 AI 推荐, 不是关键词搜索. 关键词搜索请用 `douyin hashtag search --keyword <词>`.');
        }
    }
}

cli({
    site: 'douyin',
    name: 'hashtag',
    access: 'read',
    description: '话题搜索 / AI推荐 / 热点词',
    domain: 'creator.douyin.com',
    strategy: Strategy.COOKIE,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide a keyword: `opencli douyin hashtag search --keyword 美食`
  2. Trim/validate the variable in your script before invoking
  3. If you meant AI recommendations from a video cover, use the `suggest` action with --cover instead

Example fix

// before
opencli douyin hashtag search --keyword "$KW"  // KW empty
// after
opencli douyin hashtag search --keyword "${KW:?需要 --keyword}"
Defensive patterns

Strategy: validation

Validate before calling

const keyword = (process.env.KW ?? '').trim();
if (!keyword) throw new Error('keyword is required for hashtag search');

Type guard

const hasKeyword = (kw) => typeof kw === 'string' && kw.trim().length > 0;

Try / catch

try {
  await cli.hashtag({ action: 'search', keyword });
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('search 需要 --keyword')) {
    console.error('Usage: opencli douyin hashtag search --keyword <词>');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `douyin hashtag search` without `--keyword`, with `--keyword ""`, or with a whitespace-only value (`--keyword " "` — trimmed to empty).

Common situations: Script variables that are empty/unset, forgetting the flag when copy-pasting commands, or confusing search (keyword-based) with suggest (cover-based).

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/75b217a080a4a68d. Report an issue: GitHub.