DIYgod/RSSHub · error · Error
Unknown nav: ${nav}
Error message
Unknown nav: ${nav} What it means
Thrown by the Douban channel subject route when the `nav` path parameter is not one of the four supported values ('0' through '3', mapping to 电影/电视剧/书籍/唱片). The route uses a switch statement with string literal cases; any other value falls through to the default case which throws a plain Error (not InvalidParameterError).
Source
Thrown at lib/routes/douban/channel/subject.ts:64
const channel_name = channel_info_response.data.title;
const data = response.data.modules[nav].payload.subjects;
let nav_name: string;
switch (nav) {
case '0':
nav_name = '电影';
break;
case '1':
nav_name = '电视剧';
break;
case '2':
nav_name = '书籍';
break;
case '3':
nav_name = '唱片';
break;
default:
throw new Error(`Unknown nav: ${nav}`);
}
return {
title: `豆瓣${channel_name}频道-${nav_name}推荐`,
link,
description: `豆瓣${channel_name}频道书影音下的${nav_name}推荐`,
item: data.map(({ title, extra, cover_img, url }) => {
const rate = extra.rating_group.rating ? `${extra.rating_group.rating.value.toFixed(1)}分` : extra.rating_group.null_rating_reason;
const description = `标题:${title} <br> 信息:${extra.short_info} <br> 评分:${rate} <br> <img src="${cover_img.url}">`;
return {
title,
description,
link: url,
};
}),View on GitHub (pinned to bed535e087)
Solutions
- Use only valid nav values: 0 (电影/Movie), 1 (电视剧/TV), 2 (书籍/Book), 3 (唱片/Music).
- Check the route description table for the mapping.
- Verify the nav value is a string '0'–'3', not a number or other format.
Example fix
// before
switch (nav) {
case '0': ... break;
// ...
default: throw new Error(`Unknown nav: ${nav}`);
}
// after — use InvalidParameterError with valid options
const navMap: Record<string, string> = { '0': '电影', '1': '电视剧', '2': '书籍', '3': '唱片' };
const nav_name = navMap[nav];
if (!nav_name) {
throw new InvalidParameterError(`Unknown nav: ${nav}. Valid values: 0, 1, 2, 3`);
} Defensive patterns
Strategy: validation
Validate before calling
const validNavValues = ['0', '1', '2', '3'];
function isValidDoubanNav(nav: string): boolean {
return validNavValues.includes(nav);
}
if (!isValidDoubanNav(nav)) {
throw new Error(`Invalid nav '${nav}'. Valid: 0 (Movie), 1 (TV), 2 (Book), 3 (Music)`);
} Type guard
function isDoubanNav(value: string): value is '0' | '1' | '2' | '3' {
return ['0', '1', '2', '3'].includes(value);
} Try / catch
try {
const feed = await fetch(`${rsshubUrl}/douban/channel/${id}/subject/${nav}`);
} catch (e) {
if (e.message.includes('Unknown nav')) {
console.error(`Nav must be 0-3, got: ${nav}`);
}
throw e;
} Prevention
- Always validate nav is a string '0' through '3' before using it.
- Do not pass integers or padded numbers like '00'.
- Check the route description table for the category-to-number mapping.
When it happens
Trigger: Calling /douban/channel/<id>/subject/<nav> where nav is 4, 5, 'movie', or any non-{0,1,2,3} value; passing a floating-point or padded number like '00' that doesn't match the string literal.
Common situations: Developer guesses the nav parameter instead of reading the route description table; a new subject category was added by Douban but not mapped in this route.
Related errors
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/3020d83367074dda.
Report an issue: GitHub.