DIYgod/RSSHub · error
Invalid type: ${requestedType}. Valid types are: ${validType
Error message
Invalid type: ${requestedType}. Valid types are: ${validTypes} What it means
The SIS (School of International Studies) counterpart of error 678. The handler parses the `:type` path parameter as an integer, looks it up in `categoryMap`, and on a miss throws with the requested type plus the full list of valid types. Identical pattern, different category set.
Source
Thrown at lib/routes/zju/sis/index.ts:143
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |`,
maintainers: ['Alex222222222222'],
handler: handleSisRequest,
url: 'www.sis.zju.edu.cn',
};
/**
* Main handler function for processing SIS (School of International Studies) news requests
* @param ctx - The request context containing route parameters
* @returns Promise with RSS feed data including title, link, and news items
*/
async function handleSisRequest(ctx) {
const requestedType = Number.parseInt(ctx.req.param('type'));
const categoryInfo = categoryMap.get(requestedType);
// Validate the requested category type
if (!categoryInfo) {
const validTypes = categoryMap.keys().toArray().join(', ');
throw new Error(`Invalid type: ${requestedType}. Valid types are: ${validTypes}`);
}
const categoryUrl = `${base}${categoryInfo.id}`;
// Fetch news items from all relevant categories
const allNewsItems = await fetchNewsItemsByCategory(categoryInfo.id);
// Enrich each news item with detailed content
const enrichedItems = await Promise.all(allNewsItems.map((item) => enrichNewsItemWithDetails(item, categoryUrl)));
return {
title: categoryInfo.title,
link: categoryUrl,
item: enrichedItems,
};
}
View on GitHub (pinned to bed535e087)
Solutions
- Use one of the valid type numbers listed in the error message (consult the SIS route's category table).
- Confirm the number against the SIS-specific table — it is not interchangeable with the math route's types.
- Validate that the input is numeric before it reaches the route to avoid `NaN` coercion.
Example fix
// before — wrong / non-numeric type for SIS // GET /zju/sis/99 -> Invalid type: 99. Valid types are: ... // GET /zju/sis/news -> Invalid type: NaN ... // after — valid SIS type // GET /zju/sis/0
Defensive patterns
Strategy: validation
Validate before calling
function validateSisType(raw, categoryMap) {
const type = Number.parseInt(raw, 10);
if (!Number.isFinite(type) || !categoryMap.has(type)) {
throw new Error(`Invalid type: ${raw}. Valid: ${[...categoryMap.keys()].join(', ')}`);
}
return type;
} Type guard
function isValidSisType(raw: string, categoryMap: Map<number, unknown>): raw is `${number}` {
const n = Number.parseInt(raw, 10);
return Number.isFinite(n) && categoryMap.has(n);
} Prevention
- Validate the type is a finite integer present in the SIS categoryMap before lookup.
- Guard against non-numeric input to avoid silent NaN coercion.
- Remember SIS types are a different set from math types — validate against the right map.
When it happens
Trigger: The caller requests a `type` not present in the SIS route's `categoryMap` — an out-of-range integer, a non-numeric string that `Number.parseInt` turns into `NaN`, or a category code the SIS route doesn't model.
Common situations: User supplies a type number outside the documented range; passes a category name/label instead of its numeric code; copies a type valid for the math route but not for SIS. `NaN` from non-numeric input is the usual culprit.
Related errors
- Invalid type: ${type}. Valid types are: ${validTypes}
- id not allowed
- Invalid type parameter
- Invalid type parameter
- Invalid category: ${category}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/5aacbd8b0d175ae2.
Report an issue: GitHub.