DIYgod/RSSHub · warning · Error

Invalid category: ${category}

Error message

Invalid category: ${category}

What it means

Thrown by the CAGS (Chinese Academy of Governance Sciences) edu route when `category` is not a key in the `titles` map. Valid keys are tzgg, ywjx, zs_bss, zs_sss, zs_dxsxly (matching the description table). Uses a plain `Error`, not `InvalidParameterError`.

Source

Thrown at lib/routes/cags/edu/index.ts:49

    name: '研究生院',
    maintainers: ['Chikit-L'],
    radar: [
        {
            source: ['edu.cags.ac.cn/'],
        },
    ],
    handler,
    description: `| 通知公告 | 要闻简讯 | 博士生招生 | 硕士生招生 | 大学生夏令营 |
| -------- | -------- | ---------- | ---------- | ------------ |
| tzgg     | ywjx     | zs\\_bss    | zs\\_sss    | zs\\_dxsxly   |`,
};

async function handler(ctx) {
    const category = ctx.req.param('category');
    const title = titles[category];

    if (!title) {
        throw new Error(`Invalid category: ${category}`);
    }

    const API_URL = `${host}/api/cms/cmsNews/pageByCmsNavBarId/${category}/1/10/0`;
    const response = await ofetch(API_URL);
    const data = response.data;

    const items = data.map((item) => {
        const id = item.id;
        const title = item.title;

        let pubDate: Date | null = null;
        if (item.publishDate) {
            pubDate = parseDate(item.publishDate, 'YYYY-MM-DD');
            pubDate = timezone(pubDate, 8);
        }

        const link = `${host}/#/dky/view/id=${id}/barId=${category}`;

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of: tzgg, ywjx, zs_bss, zs_sss, zs_dxsxly (literal underscores, no backslash).
  2. Maintainers: use `InvalidParameterError` and verify the description table does not mislead users with the markdown-escaped backslash-underscore.

Example fix

// before
/cags/edu/zs\_bss
// after
/cags/edu/zs_bss
Defensive patterns

Strategy: validation

Validate before calling

const CAGS_CATEGORIES = ['tzgg', 'ywjx', 'zs_bss', 'zs_sss', 'zs_dxsxly'] as const;
function validateCagsCategory(c: string): void {
    if (!(CAGS_CATEGORIES as readonly string[]).includes(c)) {
        throw new Error(`Invalid category '${c}'. Use one of: ${CAGS_CATEGORIES.join(', ')}`);
    }
}

Type guard

const CAGS_CATEGORIES = ['tzgg', 'ywjx', 'zs_bss', 'zs_sss', 'zs_dxsxly'] as const;
type CagsCategory = typeof CAGS_CATEGORIES[number];
function isCagsCategory(v: string): v is CagsCategory {
    return (CAGS_CATEGORIES as readonly string[]).includes(v);
}

Prevention

When it happens

Trigger: Calling `/cags/edu/<category>` with a value outside {tzgg, ywjx, zs_bss, zs_sss, zs_dxsxly}. Note the description table escapes underscores as `zs\_bss`; the real param uses a literal underscore.

Common situations: Copy-pasting the markdown-escaped value `zs\_bss` verbatim (including the backslash), or dropping the underscore (`zsbss`).

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/11e0f28cc5077edc. Report an issue: GitHub.