{"record":{"id":"f8276ecb01f5a3e7","repo":"DIYgod/RSSHub","slug":"invalid-type-parameter","errorCode":null,"errorMessage":"Invalid type parameter","messagePattern":"Invalid type parameter","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/routes/buct/gr.ts","lineNumber":63,"sourceCode":"\n    switch (type) {\n        case 'tzgg':\n            currentUrl = `${rootUrl}/1392/list.htm`;\n\n            break;\n\n        case 'jzml':\n            currentUrl = `${rootUrl}/jzml/list.htm`;\n\n            break;\n\n        case 'xgzc':\n            currentUrl = `${rootUrl}/1393/list.htm`;\n\n            break;\n\n        default:\n            throw new Error('Invalid type parameter');\n    }\n\n    const response = await got.get(currentUrl);\n\n    const $ = load(response.data);\n    const list = $('ul.wp_article_list > li.list_item')\n        .toArray()\n        .map((item): DataItem => ({\n            pubDate: $(item).find('.Article_PublishDate').text(),\n            title: $(item).find('a').attr('title')!,\n            link: `${rootUrl}${$(item).find('a').attr('href')}`,\n        }));\n\n    const items = await Promise.all(\n        list.map((item) =>\n            cache.tryGet(item.link!, async () => {\n                const detailResponse = await got.get(item.link);\n                const content = load(detailResponse.data);","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/buct/gr.ts#L45-L81","documentation":"Thrown by the BUCT (Beijing University of Chemical Technology) 'gr' route when the `type` path parameter does not match either 'jzml' or 'xgzc'. The handler uses a switch statement and falls through to a `default` case that raises a plain `Error('Invalid type parameter')` instead of RSSHub's `InvalidParameterError`, so downstream it surfaces as a generic 500 rather than a clean 400. It is purely an input-validation guard: the value is never sent to the remote server.","triggerScenarios":"Requesting `/buct/gr/<anything-other-than-jzml-or-xgzc>`, e.g. `/buct/gr/tzgg`, `/buct/gr/news`, `/buct/gr/` (empty). Any path segment that the switch does not explicitly case.","commonSituations":"Copying a type value from a different BUCT route (e.g. the `bupt/jwc` route uses tzgg/xwzx), outdated third-party docs listing removed categories, URL-encoding artifacts, or a trailing slash producing an empty param.","solutions":["Use only the two documented values: `/buct/gr/jzml` or `/buct/gr/xgzc`.","If you maintain this route, replace `throw new Error(...)` with `throw new InvalidParameterError('Invalid type parameter')` and enumerate allowed values in the route `description` table.","Verify the param against the switch's case labels (jzml, xgzc) before constructing the request."],"exampleFix":"// before\nthrow new Error('Invalid type parameter');\n// after\nimport InvalidParameterError from '@/errors/types/invalid-parameter';\nthrow new InvalidParameterError('Invalid type parameter. Supported: jzml, xgzc');","handlingStrategy":"validation","validationCode":"const BUCT_GR_TYPES = ['jzml', 'xgzc'] as const;\nfunction validateBuctType(type: string): void {\n    if (!BUCT_GR_TYPES.includes(type as any)) {\n        throw new Error(`Invalid type '${type}'. Use one of: ${BUCT_GR_TYPES.join(', ')}`);\n    }\n}","typeGuard":"const BUCT_GR_TYPES = ['jzml', 'xgzc'] as const;\ntype BuctGrType = typeof BUCT_GR_TYPES[number];\nfunction isBuctGrType(v: string): v is BuctGrType {\n    return (BUCT_GR_TYPES as readonly string[]).includes(v);\n}","tryCatchPattern":null,"preventionTips":["Document the allowed type values in the route description table so callers see them at /buct.","Prefer `InvalidParameterError` over plain `Error` for input-validation failures so RSSHub returns a 400.","If you consume this feed programmatically, validate the path segment against the constant list before issuing the request."],"tags":["validation","user-input","route-parameter","switch-default"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}