DIYgod/RSSHub · warning · Error

Invalid k: k=${k}

Error message

Invalid k: k=${k}

What it means

Thrown by the MissKON 'top k days' route when :k is not one of '3','7','30','60'. It is a bare `throw new Error` (not an InvalidParameterError), so it surfaces as a generic error rather than RSSHub's structured invalid-parameter response. The route only supports four pre-defined windows that map to misskon.com/topN/ pages.

Source

Thrown at lib/routes/misskon/top.ts:49

            target: '/top/7',
        },
        {
            title: 'Top 30 days',
            source: ['misskon.com/top30/'],
            target: '/top/30',
        },
        {
            title: 'Top 60 days',
            source: ['misskon.com/top60/'],
            target: '/top/60',
        },
    ],
    name: 'Top k days',
    maintainers: ['Urabartin'],
    handler: async (ctx) => {
        const { k } = ctx.req.param();
        if (!['3', '7', '30', '60'].includes(k)) {
            throw new Error(`Invalid k: k=${k}`);
        }
        const topLink = `https://misskon.com/top${k}/`;
        const response = await ofetch(topLink);
        const $ = load(response);

        const feedTitle = $('.page-title').text();
        const feedDesc = $('.content > p').first().text();
        const itemSlugs = $('#main-content article.item-list > h2 a')
            .toArray()
            .map((link) => new URL($(link).attr('href') || '').pathname.slice(1, -1));
        const searchParams = new URLSearchParams();
        searchParams.set('slug', itemSlugs.join(','));
        searchParams.set('per_page', itemSlugs.length.toString());
        return {
            title: `MissKON - ${feedTitle}`,
            link: topLink,
            description: feedDesc,
            item: await getPosts(searchParams),

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the supported values: /misskon/top/3, /misskon/top/7, /misskon/top/30, or /misskon/top/60.
  2. If you maintain the route, consider throwing InvalidParameterError instead of a bare Error so the response is structured.
  3. Validate k in any client before constructing the feed URL.

Example fix

// before
if (!['3', '7', '30', '60'].includes(k)) {
    throw new Error(`Invalid k: k=${k}`);
}

// after — use the structured error type
import InvalidParameterError from '@/errors/types/invalid-parameter';
if (!['3', '7', '30', '60'].includes(k)) {
    throw new InvalidParameterError(`Invalid k: k=${k}. Must be one of 3, 7, 30, 60.`);
}
Defensive patterns

Strategy: validation

Validate before calling

const { k } = ctx.req.param();
if (!['3', '7', '30', '60'].includes(k)) {
    throw new InvalidParameterError(`k must be one of 3, 7, 30, 60; got: ${k}`);
}

Type guard

function isValidK(k: string): k is '3' | '7' | '30' | '60' {
    return ['3', '7', '30', '60'].includes(k);
}

Prevention

When it happens

Trigger: Caller requests /misskon/top/<k> with k = '10', '100', '0', or any non-whitelisted value. The includes() check fails and it throws before fetching.

Common situations: User guesses a value (e.g. /misskon/top/10); URL builder defaults k incorrectly; user passes an empty or negative number.

Related errors


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