{"record":{"id":"ddcbe86757b9312e","repo":"DIYgod/RSSHub","slug":"invalid-type-category","errorCode":null,"errorMessage":"Invalid type: ${category}","messagePattern":"Invalid type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/gamersky/ent.ts","lineNumber":48,"sourceCode":"        supportScihub: false,\n    },\n    radar: Array.from(idNameMap, ([type, { title, suffix }]) => ({\n        title,\n        source: [`www.gamersky.com/${suffix}`],\n        target: `/ent/${type}`,\n    })),\n    name: '娱乐',\n    maintainers: ['LogicJake'],\n    description: mdTableBuilder(Array.from(idNameMap, ([type, { title, nodeId }]) => ({ type, name: title, nodeId }))),\n    handler,\n};\n\nasync function handler(ctx: Context) {\n    const category = ctx.req.param('category') ?? 'all';\n\n    const idName = idNameMap.get(category);\n    if (!idName) {\n        throw new Error(`Invalid type: ${category}`);\n    }\n\n    const response = await getArticleList(idName.nodeId);\n    const list = parseArticleList(response);\n    const fullTextList = await Promise.all(list.map((item) => getArticle(item)));\n    return {\n        title: `${idName.title} - 游民娱乐`,\n        link: `https://www.gamersky.com/${idName.suffix}`,\n        item: fullTextList,\n    };\n}\n","sourceCodeStart":30,"sourceCodeEnd":60,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/gamersky/ent.ts#L30-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst idName = idNameMap.get(category);\nif (!idName) {\n    throw new Error(`Invalid type: ${category}`);\n}\n\n// after\nconst idName = idNameMap.get(category.trim());\nif (!idName) {\n    const valid = Array.from(idNameMap.keys()).join(', ');\n    throw new InvalidParameterError(`Invalid category \"${category}\". Valid: ${valid}`);\n}","handlingStrategy":"validation","validationCode":"const validCategories = Array.from(idNameMap.keys());\nif (!validCategories.includes(category.trim())) {\n  throw new InvalidParameterError(`Invalid category. Valid: ${validCategories.join(', ')}`);\n}","typeGuard":"const isValidCategory = (c: string): c is string => idNameMap.has(c);","tryCatchPattern":null,"preventionTips":["Surface the list of valid categories in the error message.\nTrim user input before lookup.\nKeep the route description (mdTableBuilder) in sync with idNameMap."],"tags":["validation","user-input","enum"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}