{"record":{"id":"e753c59e9bdd9e43","repo":"DIYgod/RSSHub","slug":"invalid-type-type-e753c5","errorCode":null,"errorMessage":"Invalid type: ${type}","messagePattern":"Invalid type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/gamersky/news.ts","lineNumber":82,"sourceCode":"    },\n    radar: [\n        {\n            source: ['www.gamersky.com/news'],\n            target: '/news',\n        },\n    ],\n    name: '资讯',\n    maintainers: ['yy4382'],\n    description: mdTableBuilder(idNameMap),\n    handler,\n};\n\nasync function handler(ctx: Context) {\n    const type = ctx.req.param('type') ?? 'pc';\n\n    const idName = idNameMap.find((item) => item.type === type);\n    if (!idName) {\n        throw new Error(`Invalid type: ${type}`);\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.name} - 游民星空`,\n        link: 'https://www.gamersky.com/news',\n        item: fullTextList,\n    };\n}\n","sourceCodeStart":64,"sourceCodeEnd":94,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/gamersky/news.ts#L64-L94","documentation":"The Gamersky news route accepts a type path parameter (default 'pc') and searches a static idNameMap array for a matching type. If no entry has that type, the route throws 'Invalid type: {type}'. This prevents constructing a request with an unknown nodeId.","triggerScenarios":"Requesting /gamersky/news/{type} with a type not present in idNameMap — a typo, an archived news section, or a value intended for a different Gamersky route (ent/review).","commonSituations":"Users guessing type names; Gamersky restructuring news sections; copy-pasting a type from documentation for a different route.","solutions":["Consult the route description (mdTableBuilder of idNameMap) for the exact valid type strings.","If the desired section was renamed, update idNameMap or switch to the new type code.","Normalize the input (trim) before the find() call."],"exampleFix":"// before\nconst idName = idNameMap.find((item) => item.type === type);\nif (!idName) {\n    throw new Error(`Invalid type: ${type}`);\n}\n\n// after\nconst idName = idNameMap.find((item) => item.type === type.trim());\nif (!idName) {\n    const valid = idNameMap.map((i) => i.type).join(', ');\n    throw new InvalidParameterError(`Invalid type \"${type}\". Valid: ${valid}`);\n}","handlingStrategy":"validation","validationCode":"const validTypes = idNameMap.map((i) => i.type);\nif (!validTypes.includes(type.trim())) {\n  throw new InvalidParameterError(`Invalid type. Valid: ${validTypes.join(', ')}`);\n}","typeGuard":"const isValidType = (t: string): t is string => idNameMap.some((i) => i.type === t);","tryCatchPattern":null,"preventionTips":["Include valid types in the error message.\nTrim input before the find() call.\nDifferentiate this route's types from ent/review types in docs."],"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"}