DIYgod/RSSHub · error · InvalidParameterError

Invalid rank type

Error message

Invalid rank type

What it means

InvalidParameterError thrown by the xsijishe rank handler when ctx.req.param('type') is neither 'weekly' nor 'monthly' — the only two leaderboards the site exposes. The type maps to both a display title and a list index (0 or 1) used to select the correct ul li element via .eq(index).

Solutions

  1. Use 'weekly' or 'monthly'.
  2. Confirm the site still offers both boards by visiting the portal.php page; if it changed, update the if/else chain and the index mapping.
Defensive patterns

Strategy: validation

Validate before calling

const RANK_TYPES = { weekly: { title: '司机社综合周排行榜', index: 0 }, monthly: { title: '司机社综合月排行榜', index: 1 } } as const;
function resolveRankType(raw: string) {
    if (!Object.hasOwn(RANK_TYPES, raw)) {
        throw new InvalidParameterError(`Invalid rank type "${raw}". Use 'weekly' or 'monthly'.`);
    }
    return RANK_TYPES[raw as keyof typeof RANK_TYPES];
}

Type guard

function isRankType(value: string): value is 'weekly' | 'monthly' {
    return value === 'weekly' || value === 'monthly';
}

Prevention

When it happens

Trigger: A request to /xsijishe/rank/:type where type is not 'weekly' or 'monthly' (e.g. /xsijishe/rank/daily, /xsijishe/rank/yearly). Validated before launching Playwright, so no browser session is wasted.

Common situations: Caller assumed more granular timeframes exist; typo; integrator copied a type from another BBS route.

Related errors


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

Appendix: source

Thrown at lib/routes/xsijishe/rank.ts:60

    },
    name: '排行榜',
    maintainers: ['akynazh', 'AiraNadih'],
    handler,
};

async function handler(ctx) {
    const rankType = ctx.req.param('type');
    let title;
    let index;

    if (rankType === 'weekly') {
        title = '司机社综合周排行榜';
        index = 0;
    } else if (rankType === 'monthly') {
        title = '司机社综合月排行榜';
        index = 1;
    } else {
        throw new InvalidParameterError('Invalid rank type');
    }

    const context = await playwright();
    const url = `${baseUrl}/portal.php`;
    try {
        const data = await playwrightGet(url, context, '.nex_recon_lists', {
            cookie: config.xsijishe.cookie,
            userAgent: config.xsijishe.userAgent,
        });
        const $ = load(data);
        const items = $('.nex_recon_lists ul li')
            .eq(index)
            .find('.nex_recons_demens dl dd')
            .toArray()
            .map((item) => {
                const $item = $(item);
                const title = $item.find('h5').text().trim();
                const link = $item.find('a').attr('href');

View on GitHub (pinned to bed535e087)