DIYgod/RSSHub · warning · InvalidParameterError
Invalid category: ${categoryParam}. Valid categories are: ${
Error message
Invalid category: ${categoryParam}. Valid categories are: ${Object.keys(CATEGORY_SLUG_TO_ID).join(', ')} What it means
InvalidParameterError thrown by the baselang blog route when an optional :category parameter is supplied but not a key of CATEGORY_SLUG_TO_ID. The route lowercases the param first, then checks Object.hasOwn, so the error lists all valid slugs.
Source
Thrown at lib/routes/baselang/index.ts:81
},
radar: [
{
source: ['baselang.com/blog', 'baselang.com/blog/:category'],
target: '/blog/:category',
},
],
name: 'Blog',
maintainers: ['johan456789'],
handler,
};
async function handler(ctx: Context): Promise<Data> {
const categoryParam = (ctx.req.param('category') ?? '').toLowerCase();
logger.debug(`BaseLang: received request, category='${categoryParam || 'all'}'`);
if (categoryParam && !Object.hasOwn(CATEGORY_SLUG_TO_ID, categoryParam)) {
logger.debug(`BaseLang: invalid category '${categoryParam}'`);
throw new InvalidParameterError(`Invalid category: ${categoryParam}. Valid categories are: ${Object.keys(CATEGORY_SLUG_TO_ID).join(', ')}`);
}
const searchParams: string[] = ['per_page=20', '_embed=author,wp:term'];
if (categoryParam) {
const id = CATEGORY_SLUG_TO_ID[categoryParam];
searchParams.push(`categories=${id}`);
}
const apiUrl = `${API_BASE}/posts?${searchParams.join('&')}`;
const data = await ofetch<WordpressPost[]>(apiUrl);
logger.debug(`BaseLang: fetched ${data.length} posts`);
const items = data.map((post) => ({
title: post.title?.rendered,
description: post.content?.rendered ?? post.excerpt?.rendered ?? '',
link: post.link,
pubDate: parseDate(post.date_gmt ?? post.date),View on GitHub (pinned to bed535e087)
Solutions
- Use one of the slugs in the error message (advanced-grammar, basic-grammar, company, confidence, french, humor, medellin, motivation, pronunciation, study-tips, success-stories, travel, uncategorized, vocabulary), or omit the category.
- If the WordPress site has a new category, find its WP term id and add it to CATEGORY_SLUG_TO_ID.
Defensive patterns
Strategy: validation
Validate before calling
const categoryParam = (ctx.req.param('category') ?? '').toLowerCase();
if (categoryParam && !Object.hasOwn(CATEGORY_SLUG_TO_ID, categoryParam)) {
throw new InvalidParameterError(`Invalid category: ${categoryParam}. Valid: ${Object.keys(CATEGORY_SLUG_TO_ID).join(', ')}`);
} Type guard
function isKnownCategory(slug: string): slug is keyof typeof CATEGORY_SLUG_TO_ID {
return Object.prototype.hasOwnProperty.call(CATEGORY_SLUG_TO_ID, slug);
} Prevention
- Lowercase the param before lookup so case variants do not fail.
- Expose CATEGORY_OPTIONS via parameters.options so valid slugs are discoverable.
When it happens
Trigger: Calling /baselang/blog/:category with a slug not in CATEGORY_SLUG_TO_ID (e.g. 'news', 'spanish', or a typo). Omitting category is fine and returns all posts.
Common situations: User guesses a slug that the WordPress site uses but the route never mapped; case differences are already handled by toLowerCase, so this usually means a genuinely unmapped category.
Related errors
- Invalid id: ${id}. Allowed values are: ${[...validIds].join(
- Invalid language: ${language}. Allowed values are: ${[...val
- 无效的排序类型
- 关键词不能为空
- Unsupported server
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/07318529ac5c630e.
Report an issue: GitHub.