DIYgod/RSSHub · warning · InvalidParameterError

invalid type

Error message

invalid type

What it means

InvalidParameterError from the NJUST Computer Science route. The handler reads ctx.req.param('type') (default 'xyxw'), looks it up in a Map, and throws if undefined. This is the idiomatic RSSHub pattern for type validation and correctly returns a 400-class error.

Source

Thrown at lib/routes/njust/cs.ts:43

        requirePuppeteer: true,
        antiCrawler: false,
        supportBT: false,
        supportPodcast: false,
        supportScihub: false,
    },
    name: '计算机学院',
    maintainers: ['Horacecxk', 'jasongzy'],
    handler,
    description: `| 学院新闻 | 通知公告 | 学术动态 |
| -------- | -------- | -------- |
| xyxw     | tzgg     | xsdt     |`,
};

async function handler(ctx) {
    const type = ctx.req.param('type') ?? 'xyxw';
    const info = map.get(type);
    if (!info) {
        throw new InvalidParameterError('invalid type');
    }
    const id = info.id;
    const siteUrl = host + id + '/list.htm';
    const html = await getContent(siteUrl, true);
    const $ = load(html);
    const list = $('div#wp_news_w9').find('a');

    return {
        title: info.title,
        link: siteUrl,
        item: list.toArray().map((item) => ({
            title: $(item).find('span[class="column-news-title"]').text().trim(),
            pubDate: timezone(parseDate($(item).find('span[class="column-news-date news-date-hide"]').text(), 'YYYY-MM-DD'), 8),
            link: $(item).attr('href'),
        })),
    };
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the documented codes for this route: xyxw (学院新闻), tzgg (通知公告), xsdt (学术动态).
  2. Do not assume codes are shared across NJUST sub-sites — each route has its own map.
  3. Check the route's description table for the authoritative list.

Example fix

// before
const info = map.get(type);
if (!info) {
    throw new InvalidParameterError('invalid type');
}

// after — caller fix
//   GET /njust/cs/xyxw   ✓
//   GET /njust/cs/tzgg   ✓
Defensive patterns

Strategy: validation

Validate before calling

const VALID = new Set(['xyxw','tzgg','xsdt']);
function buildNjustCsUrl(type) {
  if (!VALID.has(type)) throw new Error(`invalid type '${type}'. Valid: ${[...VALID].join(', ')}`);
  return host + MAP[type] + '/list.htm';
}

Type guard

const isCsType = (t: string): t is 'xyxw'|'tzgg'|'xsdt' => VALID.has(t);

Prevention

When it happens

Trigger: Calling /njust/cs/:type with a value not present in the route's map — e.g. typo, or a category that exists on another NJUST sub-site but not CS. Valid keys for this route are xyxw / tzgg / xsdt (per the description table).

Common situations: User mistypes the code; user copies a type from a sibling NJUST route (cwc, dgxg, eoe, jwc) that uses different keys.

Related errors


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