DIYgod/RSSHub · error · Error

Invalid type

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.

Solutions

  1. Check the route description (mdTableBuilder output) for the list of valid category codes and use one of those.
  2. If a previously-valid category was removed, update idNameMap in the source or pick a replacement.
  3. 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

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


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

Appendix: 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)