DIYgod/RSSHub · error · Error
Unknown category: ${category}. Valid: ${Object.keys(category
Error message
Unknown category: ${category}. Valid: ${Object.keys(categoryMap).join(', ')} What it means
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.
Source
Thrown at lib/routes/sjtu/cs/tzgg.tsx:109
},
radar: Object.entries(categoryMap).map(([key, { code }]) => ({
source: [`www.cs.sjtu.edu.cn/${code}.html`],
target: `/cs/tzgg/${key}`,
})),
name: '计算机学院 - 通知公告',
maintainers: ['BeaCox'],
handler,
url: 'www.cs.sjtu.edu.cn/notice-xssw-bkspy.html',
description: `| 本科生培养 | 研究生培养 | 国际交流 | 党建德育 | 团学工作 | 职业发展 | 其他 |
| ---------- | ---------- | -------- | -------- | -------- | -------- | ---- |
| bkspy | yjspy | gjjl | djdy | txgz | zyfz | qt |`,
};
async function handler(ctx): Promise<Data> {
const category = ctx.req.param('category');
const cat = categoryMap[category];
if (!cat) {
throw new Error(`Unknown category: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}`);
}
const listLink = `${host}/${cat.code}.html`;
const json = await ofetch<{ content: string; count: number }>(ajaxUrl, {
method: 'POST',
body: new URLSearchParams({
page: '1',
cat_code: cat.code,
type: '',
search: '',
extend_id: '0',
template: 'ajax_news_list1_search',
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
parseResponse: JSON.parse,
});View on GitHub (pinned to bed535e087)
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.
Example fix
// before
if (!cat) {
throw new Error(`Unknown category: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}`);
}
// after
import InvalidParameterError from '@/errors/types/invalid-parameter';
// ...
if (!cat) {
throw new InvalidParameterError(`Unknown category: ${category}. Valid: ${Object.keys(categoryMap).join(', ')}`);
} Defensive patterns
Strategy: validation
Validate before calling
const validCategories = ['bkspy', 'yjspy', 'gjjl', 'djdy', 'txgz', 'zyfz', 'qt'];
if (!validCategories.includes(category)) {
// do not call the route; surface valid options to the user
return { error: `Invalid category. Valid options: ${validCategories.join(', ')}` };
} Type guard
const isSjtuCategory = (v: string): v is 'bkspy' | 'yjspy' | 'gjjl' | 'djdy' | 'txgz' | 'zyfz' | 'qt' =>
['bkspy', 'yjspy', 'gjjl', 'djdy', 'txgz', 'zyfz', 'qt'].includes(v); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid parameter brief. Please check the doc https://docs.r
- invalid keyId
- The column ${columnParam} does not exist
- The column ${columnParam} does not exist
- The column ${columnParam} does not exist
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/988bd5cc4063a524.
Report an issue: GitHub.