DIYgod/RSSHub · error · InvalidParameterError

Bad type. See <a href="https://docs.rsshub.app/routes/new-me

Error message

Bad type. See <a href="https://docs.rsshub.app/routes/new-media#it-zhi-jia">https://docs.rsshub.app/routes/new-media#it-zhi-jia</a>

What it means

Thrown by the ithome ranking route as `InvalidParameterError('Bad type')` when the `type` path param is not a key in the `type2id` map. Valid types are `24h`, `7days`, `monthly` (mapped to ranking-section ids `d-1`, `d-2`, `d-3`).

Source

Thrown at lib/routes/ithome/ranking.ts:54

    const $ = load(response.data);

    const config = {
        '24h': '24 小时最热',
        '7days': '7 天最热',
        monthly: '月榜',
    };

    const type2id = {
        '24h': 'd-1',
        '7days': 'd-2',
        monthly: 'd-3',
    };

    const title = config[option];
    const id = type2id[option];

    if (!id) {
        throw new InvalidParameterError('Bad type. See <a href="https://docs.rsshub.app/routes/new-media#it-zhi-jia">https://docs.rsshub.app/routes/new-media#it-zhi-jia</a>');
    }

    const list = $(`#${id} > li`)
        .toArray()
        .map((item) => {
            const info: DataItem = {
                title: $(item).find('a').text(),
                link: $(item).find('a').attr('href'),
            };
            return info;
        });

    const items = await Promise.all(
        list.map((item) =>
            cache.tryGet(item.link!, async () => {
                const res = await got({
                    method: 'get',
                    url: item.link,

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the valid keys: `/ithome/ranking/24h`, `/ithome/ranking/7days`, `/ithome/ranking/monthly`.
  2. If a new ranking period is added to ithome's rank page, add the mapping to `type2id` and `config` in lib/routes/ithome/ranking.ts.

Example fix

// before: /ithome/ranking/daily
// after:  /ithome/ranking/24h
Defensive patterns

Strategy: validation

Validate before calling

const id = type2id[option];
if (!id) throw new InvalidParameterError(`Bad type. Valid: ${Object.keys(type2id).join(', ')}`);

Type guard

const isKnownRankingType = (t: string): t is keyof typeof type2id => t in type2id;

Prevention

When it happens

Trigger: Request to `/ithome/ranking/:type` where `type` is anything other than `24h`, `7days`, or `monthly` — e.g. `/ithome/ranking/daily`, `/ithome/ranking/year`, or a typo. The check `if (!id)` fires because `type2id[option]` is undefined.

Common situations: User passes a plausible-but-wrong period name (`daily`, `weekly`, `year`); typo; outdated docs.

Related errors


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