jackwener/OpenCLI · warning · ArgumentError

weread-official: type must be one of: ${Object.keys(TYPE_ALI

Error message

weread-official: type must be one of: ${Object.keys(TYPE_ALIASES).join(', ')}

What it means

This ArgumentError is thrown by `weread-official review` when the `type` argument is not one of the keys of TYPE_ALIASES (validated via hasOwnProperty). The alias map converts the user-facing type into the API's reviewListType parameter. It is a strict enum-validation error raised before any API call.

Source

Thrown at clis/weread-official/review.js:52

    name: 'review',
    access: 'read',
    description: 'Browse public reviews of a WeRead book',
    domain: 'weread.qq.com',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'bookId', positional: true, required: true, help: 'WeRead bookId (from `weread-official search`)' },
        { name: 'type', default: 'all', choices: Object.keys(TYPE_ALIASES), help: 'Review filter (all/recommend/thumbs-down/newest/neutral)' },
        { name: 'count', type: 'int', default: 20, help: 'Page size (1-100, default 20)' },
        { name: 'max-idx', type: 'int', default: 0, help: 'Pagination cursor — pass idx from last row of previous page' },
        { name: 'synckey', type: 'int', help: 'Sync cursor returned by previous response' },
    ],
    columns: ['rank', 'idx', 'reviewId', 'star', 'starLabel', 'author', 'isFinish', 'chapter', 'content', 'createTime', 'link'],
    func: async (args) => {
        const bookId = requireBookId(args.bookId);
        const typeKey = String(args.type ?? 'all').trim();
        if (!Object.prototype.hasOwnProperty.call(TYPE_ALIASES, typeKey)) {
            throw new ArgumentError(
                `weread-official: type must be one of: ${Object.keys(TYPE_ALIASES).join(', ')}`,
            );
        }
        const reviewListType = TYPE_ALIASES[typeKey];
        const count = requirePositiveInt(args.count, 'count', { defaultValue: 20, max: 100 });
        const params = { bookId, reviewListType, count, maxIdx: Number(args['max-idx'] ?? 0) };
        if (args.synckey !== undefined && args.synckey !== null && args.synckey !== '') {
            params.synckey = requirePositiveInt(args.synckey, 'synckey');
        }

        const payload = await callGateway('/review/list', params);
        const reviews = Array.isArray(payload?.reviews) ? payload.reviews : [];
        if (reviews.length === 0) {
            emptyResult('review', `No public reviews for bookId=${bookId} (type=${typeKey}).`);
        }

        return reviews.map((wrapper, i) => {
            const reviewOuter = wrapper?.review ?? {};

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the command with --help or check TYPE_ALIASES for the exact accepted keys
  2. Match the case exactly (the lookup is case-sensitive)
  3. Default is 'all' — omit --type to get all reviews
  4. Normalize your input with .toLowerCase() before passing if the aliases are lowercase

Example fix

// before
await wereadReview({ bookId, type: 'Latest' });
// after
const allowed = ['all', 'hot', 'latest']; // see TYPE_ALIASES
const t = String(type).trim().toLowerCase();
if (!allowed.includes(t)) throw new Error(`type must be one of ${allowed.join(', ')}`);
await wereadReview({ bookId, type: t });
Defensive patterns

Strategy: validation

Validate before calling

const TYPE_KEYS = ['all','hot','latest']; // mirror TYPE_ALIASES
if (!TYPE_KEYS.includes(String(type ?? 'all').trim())) throw new Error(`type must be one of: ${TYPE_KEYS.join(', ')}`);

Type guard

function isValidReviewType(t) { return typeof t === 'string' && Object.keys(TYPE_ALIASES).includes(t.trim()); }

Try / catch

try { await wereadReview(args); }
catch (e) { if (e.name === 'ArgumentError' && e.message.includes('type must be')) { printAllowedTypes(); } else throw e; }

Prevention

When it happens

Trigger: Passing `--type` with a value not in the allowed alias keys (e.g. typo like 'reviw', unsupported like 'like', or wrong casing since the check is case-sensitive and the key is trimmed but not lowercased).

Common situations: Guessing type names without checking --help; migrating from another weread tool that used different type vocabularies; scripting with a variable containing an unexpected value; capitalization differences like 'All' vs 'all'.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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