DIYgod/RSSHub · error · Error

Unknown type: ${type}

Error message

Unknown type: ${type}

What it means

Route /whu/cs/:type only accepts integer types 0–3 (学院新闻, 学术交流, 通知公告, 科研进展 per the description table). The handler Number.parseInt's the param and any value outside {0,1,2,3} — including NaN from non-numeric input — falls through to the default branch.

Source

Thrown at lib/routes/whu/cs.ts:58

            break;

        case 1:
            link = `${baseUrl}/kxyj/xsjl.htm`; // 学术交流

            break;

        case 2:
            link = `${baseUrl}/xwdt/tzgg.htm`; // 通知公告

            break;

        case 3:
            link = `${baseUrl}/kxyj/kyjz.htm`; // 科研进展

            break;

        default:
            throw new Error(`Unknown type: ${type}`);
    }

    const response = await got(link);
    const $ = load(response.data);

    const list = $('div.study ul li')
        .toArray()
        .map((item): DataItem & { link: string } => {
            const $item = $(item);
            return {
                title: $item.find('a p').text().trim(),
                pubDate: parseDate($item.find('span').text()),
                link: new URL($item.find('a').attr('href')!, link).href,
            };
        });

    let items = (await Promise.all(
        list.map((item) =>

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the documented values: 0, 1, 2, or 3 (see the route description table in cs.ts).
  2. Verify the exact path: /whu/cs/<0|1|2|3>.
  3. If you need another category, check whether /whu/rsgis or /whu/swrh covers it instead.

Example fix

// before
/whu/cs/4
// after
/whu/cs/2   // 通知公告
Defensive patterns

Strategy: validation

Validate before calling

const VALID = new Set([0, 1, 2, 3]);
const raw = ctx.req.param('type');
const type = Number.parseInt(raw, 10);
if (!Number.isInteger(type) || !VALID.has(type)) {
    throw new InvalidParameterError(`/whu/cs/:type must be one of 0,1,2,3 — got ${raw}`);
}

Type guard

function isWhuCsType(v: unknown): v is 0 | 1 | 2 | 3 {
    const n = Number(v);
    return Number.isInteger(n) && n >= 0 && n <= 3;
}

Try / catch

try {
    // ...handler body
} catch (e) {
    if (e instanceof Error && /^Unknown type:/.test(e.message)) {
        return ctx.json({ error: 'Invalid type. Use 0,1,2, or 3.' }, 400);
    }
    throw e;
}

Prevention

When it happens

Trigger: Caller requests /whu/cs/4, /whu/cs/abc, /whu/cs/-1, or omits the segment in a way that yields an unhandled value; Number.parseInt('abc') → NaN fails every case.

Common situations: Typo in the route path; copied an example for a different whu sub-route (e.g. swrh uses 0–2); aggregator passing an unsupported category id.

Related errors


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