DIYgod/RSSHub · warning · InvalidParameterError

invalid keyId

Error message

invalid keyId

What it means

Thrown as an `InvalidParameterError` when the `keyId` path parameter for the NUDT (National University of Defense Technology) graduate admissions route is not found in the `yjszs` Map. Valid keyIds are: '1', '2', '8', '12', '16', '17', '23', '25'. The handler defaults to '2' if no parameter is provided.

Source

Thrown at lib/routes/nudt/yjszs.ts:64

    radar: [
        {
            source: ['yjszs.nudt.edu.cn'],
        },
    ],
    name: '研究生院',
    maintainers: ['Blank0120'],
    handler,
    url: 'yjszs.nudt.edu.cn/',
    description: `| 通知公告 | 首页 | 招生简章 | 学校政策 | 硕士招生 | 博士招生 | 院所发文 | 数据统计 |
| -------- | ---- | -------- | -------- | -------- | -------- | -------- | -------- |
| 2        | 1    | 8        | 12       | 16       | 17       | 23       | 25       |`,
};

async function handler(ctx) {
    const keyId = ctx.req.param('keyId') ?? '2';
    const info = yjszs.get(keyId);
    if (!info) {
        throw new InvalidParameterError('invalid keyId');
    }
    let link = `${host}/pubweb/homePageList`;
    link += keyId === '2' ? '/searchContent.view' : `/recruitStudents.view?keyId=${keyId}`;
    const response = await got({
        method: 'get',
        url: link,
    });

    const $ = load(response.data);
    const content = $('.news-list li');
    const items = content.toArray().map((elem) => {
        const $elem = $(elem);
        return {
            link: new URL($elem.find('a').attr('href')!, host).href,
            title: $elem.find('h3').text().trim(),
            pubDate: timezone(parseDate($elem.find('.time').text(), 'YYYY-MM-DD'), -8),
        };
    });

View on GitHub (pinned to bed535e087)

Solutions

  1. Use only the documented keyId values: 2 (通知公告), 1 (首页), 8 (招生简章), 12 (学校政策), 16 (硕士招生), 17 (博士招生), 23 (院所发文), 25 (数据统计).
  2. Omit the keyId parameter entirely to default to '2' (通知公告).
  3. If the university added a new category, add it to the `yjszs` Map at the top of `lib/routes/nudt/yjszs.ts`.
Defensive patterns

Strategy: validation

Validate before calling

// Validate keyId against the yjszs Map before use
const validKeyIds = new Set(yjszs.keys());
if (!validKeyIds.has(keyId)) {
    throw new InvalidParameterError(
        `Invalid keyId '${keyId}'. Valid values: ${[...validKeyIds].join(', ')}`
    );
}

Type guard

function isValidKeyId(keyId: string, map: Map<string, unknown>): keyId is string {
    return map.has(keyId);
}

Prevention

When it happens

Trigger: Requesting `/nudt/yjszs/<keyId>` with a keyId that is not in the hardcoded Map (e.g., '3', '99', 'abc'). The Map maps keyIds to category titles like '通知公告', '首页', '招生简章', etc.

Common situations: User passes a keyId from the URL of a different page that isn't in the curated list. The university reorganized its pages and old keyIds were removed. User guesses a numeric value not in the supported set.

Related errors


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