DIYgod/RSSHub · warning · InvalidParameterError

Invalid category: ${category}

Error message

Invalid category: ${category}

What it means

InvalidParameterError thrown by the Plurk Top handler when the category path parameter is not in the allowed set {topReplurks, topFavorites, topResponded}. The route validates against a Set before building the /Stats/{category} URL, so an unknown category never reaches the upstream API.

Source

Thrown at lib/routes/plurk/top.ts:39

        supportPodcast: false,
        supportScihub: false,
    },
    name: 'Top',
    maintainers: ['TonyRL'],
    handler,
    description: `| Top Replurks | Top Favorites | Top Responded |
| ------------ | ------------- | ------------- |
| topReplurks  | topFavorites  | topResponded  |

| English | 中文(繁體) |
| ------- | ------------ |
| en      | zh           |`,
};

async function handler(ctx) {
    const { category = 'topReplurks', lang = 'en' } = ctx.req.param();
    if (!categoryList.has(category)) {
        throw new InvalidParameterError(`Invalid category: ${category}`);
    }

    const { data: apiResponse } = await got(`${baseUrl}/Stats/${category}`, {
        searchParams: {
            period: 'day',
            lang,
            limit: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 90,
        },
    });

    const items = await Promise.all(apiResponse.stats.map((item) => item[1]).map((item) => getPlurk(`plurk:${item.plurk_id}`, item, item.owner.display_name)));

    return {
        title: 'Top Plurk - Plurk',
        image: 'https://s.plurk.com/2c1574c02566f3b06e91.png',
        link: `${baseUrl}/top#${category}`,
        item: items,
        language: lang,

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the documented categories: topReplurks, topFavorites, or topResponded (case-sensitive).
  2. Omit the category to accept the default (topReplurks).
  3. If subscribing from a docs example, copy the value verbatim.
  4. Update any stale RSS client URLs that reference a renamed/removed category.

Example fix

// before: /plurk/top/topReplurk
// after:  /plurk/top/topReplurks
Defensive patterns

Strategy: validation

Validate before calling

const VALID_CATEGORIES = new Set(['topReplurks', 'topFavorites', 'topResponded']);
function isValidCategory(c: string): c is 'topReplurks' | 'topFavorites' | 'topResponded' {
  return VALID_CATEGORIES.has(c);
}
// before building the request:
if (!isValidCategory(category)) {
  // reject with the allowed list
}

Type guard

const isValidCategory = (c: unknown): c is 'topReplurks' | 'topFavorites' | 'topResponded' =>
  typeof c === 'string' && new Set(['topReplurks', 'topFavorites', 'topResponded']).has(c as any);

Try / catch

try {
  // plurk top handler
} catch (e) {
  if (e instanceof InvalidParameterError && /Invalid category/.test(e.message)) {
    // surface the three valid categories to the user
  }
}

Prevention

When it happens

Trigger: Passing a category value outside the three valid ones in /plurk/top/:category?/:lang?, e.g. a typo like 'topReplurk' (missing s), 'topLikes', or a localized string.

Common situations: User mistypes the category; copies a value from outdated docs; uses a singular form; passes an arbitrary string hoping for a category.

Related errors


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