DIYgod/RSSHub · error · Error
Invalid type: ${category}
Error message
Invalid type: ${category} What it means
The Gamersky entertainment route accepts a category path parameter and looks it up in a static idNameMap. If the category is not one of the predefined keys, the lookup returns undefined and the route throws 'Invalid type: {category}'. This is strict input validation to prevent fetching with an unknown nodeId.
Source
Thrown at lib/routes/gamersky/ent.ts:48
supportScihub: false,
},
radar: Array.from(idNameMap, ([type, { title, suffix }]) => ({
title,
source: [`www.gamersky.com/${suffix}`],
target: `/ent/${type}`,
})),
name: '娱乐',
maintainers: ['LogicJake'],
description: mdTableBuilder(Array.from(idNameMap, ([type, { title, nodeId }]) => ({ type, name: title, nodeId }))),
handler,
};
async function handler(ctx: Context) {
const category = ctx.req.param('category') ?? 'all';
const idName = idNameMap.get(category);
if (!idName) {
throw new Error(`Invalid type: ${category}`);
}
const response = await getArticleList(idName.nodeId);
const list = parseArticleList(response);
const fullTextList = await Promise.all(list.map((item) => getArticle(item)));
return {
title: `${idName.title} - 游民娱乐`,
link: `https://www.gamersky.com/${idName.suffix}`,
item: fullTextList,
};
}
View on GitHub (pinned to bed535e087)
Solutions
- Check the route description (mdTableBuilder output) for the list of valid category codes and use one of those.
- If a previously-valid category was removed, update idNameMap in the source or pick a replacement.
- Strip whitespace and lowercase the input before lookup if case/whitespace mismatches are likely.
Example fix
// before
const idName = idNameMap.get(category);
if (!idName) {
throw new Error(`Invalid type: ${category}`);
}
// after
const idName = idNameMap.get(category.trim());
if (!idName) {
const valid = Array.from(idNameMap.keys()).join(', ');
throw new InvalidParameterError(`Invalid category "${category}". Valid: ${valid}`);
} Defensive patterns
Strategy: validation
Validate before calling
const validCategories = Array.from(idNameMap.keys());
if (!validCategories.includes(category.trim())) {
throw new InvalidParameterError(`Invalid category. Valid: ${validCategories.join(', ')}`);
} Type guard
const isValidCategory = (c: string): c is string => idNameMap.has(c);
Prevention
- Surface the list of valid categories in the error message. Trim user input before lookup. Keep the route description (mdTableBuilder) in sync with idNameMap.
When it happens
Trigger: A user requests /gamersky/ent/{category} with a category string that is not a key in idNameMap — e.g. a typo, a deprecated category, or a value copied from a different Gamersky section. The route falls back to 'all' only implicitly via the default; any explicit-but-wrong value fails.
Common situations: Typing the category name instead of its code; Gamersky renaming or removing a category so the map no longer contains it; users assuming the parameter accepts free-form category names.
Related errors
- Invalid type: ${type}
- Invalid type: ${type}
- Bad timeRange range. See <a href="https://docs.rsshub.app/ro
- This category does not exist. Please refer to the documentat
- Invalid category Id: ${categoryId}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/ddcbe86757b9312e.
Report an issue: GitHub.