{"record":{"id":"988bd5cc4063a524","repo":"DIYgod/RSSHub","slug":"unknown-category-category-valid-object-key","errorCode":null,"errorMessage":"Unknown category: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}","messagePattern":"Unknown category: (.+?)\\. Valid: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/sjtu/cs/tzgg.tsx","lineNumber":109,"sourceCode":"    },\n    radar: Object.entries(categoryMap).map(([key, { code }]) => ({\n        source: [`www.cs.sjtu.edu.cn/${code}.html`],\n        target: `/cs/tzgg/${key}`,\n    })),\n    name: '计算机学院 - 通知公告',\n    maintainers: ['BeaCox'],\n    handler,\n    url: 'www.cs.sjtu.edu.cn/notice-xssw-bkspy.html',\n    description: `| 本科生培养 | 研究生培养 | 国际交流 | 党建德育 | 团学工作 | 职业发展 | 其他 |\n| ---------- | ---------- | -------- | -------- | -------- | -------- | ---- |\n| bkspy      | yjspy      | gjjl     | djdy     | txgz     | zyfz     | qt   |`,\n};\n\nasync function handler(ctx): Promise<Data> {\n    const category = ctx.req.param('category');\n    const cat = categoryMap[category];\n    if (!cat) {\n        throw new Error(`Unknown category: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}`);\n    }\n\n    const listLink = `${host}/${cat.code}.html`;\n    const json = await ofetch<{ content: string; count: number }>(ajaxUrl, {\n        method: 'POST',\n        body: new URLSearchParams({\n            page: '1',\n            cat_code: cat.code,\n            type: '',\n            search: '',\n            extend_id: '0',\n            template: 'ajax_news_list1_search',\n        }),\n        headers: {\n            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',\n        },\n        parseResponse: JSON.parse,\n    });","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/sjtu/cs/tzgg.tsx#L91-L127","documentation":"Thrown at lib/routes/sjtu/cs/tzgg.tsx:109 when the `:category` path parameter does not match any key in the local `categoryMap` (valid keys: bkspy, yjspy, gjjl, djdy, txgz, zyfz, qt). It is an input-validation guard executed before any HTTP call to the SJTU CS AJAX endpoint, so no network request is wasted on a bad category. Note it throws a generic `Error` rather than RSSHub's `InvalidParameterError`, which means the framework will not map it to a clean 400 response.","triggerScenarios":"Requesting `/sjtu/cs/tzgg/<invalid>` where `<invalid>` is not one of the seven enumerated category keys — e.g. `/sjtu/cs/tzgg/undergrad`, `/sjtu/cs/tzgg/bkspy/`, or any value with trailing characters, casing, or whitespace.","commonSituations":"Typo in the category slug from a copied URL; user guesses a category name instead of using the documented code; URL-encoding issues with the path segment.","solutions":["Use one of the seven documented keys: bkspy, yjspy, gjjl, djdy, txgz, zyfz, qt — see the route description table.","If maintaining the route, replace `throw new Error(...)` with `throw new InvalidParameterError(...)` so RSSHub returns a proper 400 status.","Check the radar source mapping (lines 92–95) to confirm which category key corresponds to the source URL you came from."],"exampleFix":"// before\nif (!cat) {\n    throw new Error(`Unknown category: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}`);\n}\n\n// after\nimport InvalidParameterError from '@/errors/types/invalid-parameter';\n// ...\nif (!cat) {\n    throw new InvalidParameterError(`Unknown category: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}`);\n}","handlingStrategy":"validation","validationCode":"const validCategories = ['bkspy', 'yjspy', 'gjjl', 'djdy', 'txgz', 'zyfz', 'qt'];\nif (!validCategories.includes(category)) {\n    // do not call the route; surface valid options to the user\n    return { error: `Invalid category. Valid options: ${validCategories.join(', ')}` };\n}","typeGuard":"const isSjtuCategory = (v: string): v is 'bkspy' | 'yjspy' | 'gjjl' | 'djdy' | 'txgz' | 'zyfz' | 'qt' =>\n    ['bkspy', 'yjspy', 'gjjl', 'djdy', 'txgz', 'zyfz', 'qt'].includes(v);","tryCatchPattern":null,"preventionTips":["Encode the valid category set as a shared constant so both the route and any caller-side validation reference the same source of truth.","Trim and lowercase the category parameter before validation to catch whitespace/casing issues.","Prefer InvalidParameterError over generic Error so the framework returns HTTP 400 with a structured message."],"tags":["validation","parameters","university"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}