jackwener/OpenCLI · warning · ArgumentError

Unknown category: ${value}

Error message

Unknown category: ${value}

What it means

resolveCategory matches the user-supplied value against live categories fetched from linux.do (by id, name, or slug, with parent info filled in) and throws ArgumentError when nothing matches. The hint points to `opencli linux-do categories` for the valid list. Like resolveTag, this fires only after the category metadata was successfully retrieved, so it is purely an input mismatch.

Source

Thrown at clis/linux-do/feed.js:255

    }));
}
/**
 * 解析标签,支持 id、name、slug 三种输入。
 */
async function resolveTag(page, value) {
    const liveTag = findMatchingTag(await fetchLiveTags(page), value);
    if (liveTag)
        return liveTag;
    throw new ArgumentError(`Unknown tag: ${value}`, 'Use "opencli linux-do tags" to list available tags');
}
/**
 * 解析分类,并补齐父分类信息。
 */
async function resolveCategory(page, value) {
    const liveCategory = findMatchingCategory(await fetchLiveCategories(page), value);
    if (liveCategory)
        return liveCategory;
    throw new ArgumentError(`Unknown category: ${value}`, 'Use "opencli linux-do categories" to list available categories');
}
/**
 * 将命令参数转换为最终请求地址
 */
async function resolveFeedRequest(page, kwargs) {
    const view = (kwargs.view || 'latest');
    const period = (kwargs.period || 'weekly');
    if (kwargs.period && view !== 'top') {
        throw new ArgumentError('--period is only valid with --view top');
    }
    const params = new URLSearchParams();
    if (kwargs.order && kwargs.order !== 'default')
        params.set('order', kwargs.order);
    if (kwargs.ascending)
        params.set('ascending', 'true');
    if (kwargs.limit)
        params.set('per_page', String(kwargs.limit));
    const tagValue = typeof kwargs.tag === 'string' ? kwargs.tag.trim() : '';

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run `opencli linux-do categories` and use the exact id, name, or slug shown
  2. If targeting a subcategory, use its own slug/id rather than the parent's
  3. Delete ~/.opencli/cache/linux-do/categories.json to force a refresh if the forum was recently reorganized
  4. If you meant a tag, use --tag instead of --category

Example fix

// before (shell)
opencli linux-do feed --category "开发调优"   // Unknown category: 开发调优 (renamed)
// after (shell)
opencli linux-do categories               # find current id, e.g. 94
opencli linux-do feed --category 94
Defensive patterns

Strategy: validation

Validate before calling

// Validate the category before calling the feed command
const categories = await fetchLiveCategories(page);
function isValidCategory(value) {
    const norm = s => s.trim().replace(/\s+/g, ' ').toLowerCase();
    return categories.some(c =>
        String(c.id) === value.trim() ||
        norm(c.name) === norm(value) ||
        norm(c.slug) === norm(value));
}
if (!isValidCategory(userValue)) {
    console.error('Invalid category. Run: opencli linux-do categories');
    process.exit(1);
}

Type guard

function isKnownCategory(records, value) {
    const norm = s => String(s).trim().replace(/\s+/g, ' ').toLowerCase();
    return records.some(r =>
        String(r.id) === value.trim() ||
        norm(r.name) === norm(value) ||
        norm(r.slug) === norm(value));
}

Try / catch

import { ArgumentError } from '@jackwener/opencli/errors';
try {
    await category(value);
} catch (err) {
    if (err instanceof ArgumentError && err.message.startsWith('Unknown category:')) {
        console.error(`${err.message}\n${err.hint || 'Run: opencli linux-do categories'}`);
        process.exitCode = 1;
    } else {
        throw err;
    }
}

Prevention

When it happens

Trigger: `opencli linux-do feed --category <value>` where value matches no category id, name, or slug: typo, using a subcategory display name that differs from its slug, referencing a deleted/restructured category, or passing a tag value to --category.

Common situations: linux.do reorganized categories so old names no longer resolve; user copies the Chinese display name with different spacing; using the parent name when the child slug is required; stale 24h cache after a forum restructure.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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