DIYgod/RSSHub · warning · Error
cddm should be 2 or 4 digits
Error message
cddm should be 2 or 4 digits
What it means
Generic Error validating the cddm (menu code) path parameter of /buaa/jiaowu/:cddm?. The BUAA academic-affairs CMS expects either a 2-digit fcd (parent menu) or a 4-digit cddm (child menu, whose first 2 digits are the fcd). The length check rejects anything else before it is interpolated into the newsList.do form params.
Source
Thrown at lib/routes/buaa/jiaowu.ts:49
categories: ['university'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
};
async function handler(ctx: Context): Promise<Data> {
let cddm = ctx.req.param('cddm');
if (!cddm) {
cddm = '02';
}
if (cddm.length !== 2 && cddm.length !== 4) {
throw new Error('cddm should be 2 or 4 digits');
}
const { title, list } = await getList(BASE_URL, {
id: '',
fcdTab: cddm.slice(0, 2),
cddmTab: cddm,
xsfsTab: '2',
tplbid: '',
xwid: '',
zydm: '',
zymc: '',
yxdm: '',
pyzy: '',
szzqdm: '',
});
const item = await getItems(list);
return {View on GitHub (pinned to bed535e087)
Solutions
- Provide exactly 2 digits (parent menu) or 4 digits (child menu) as documented, e.g. /buaa/jiaowu/03 or /buaa/jiaowu/0203.
- Omit cddm to use the default '02' (通知公告).
- Extract the code from the CMS page's onclick handler exactly (onNewsList('03') -> 03; onNewsList2('0203','2') -> 0203).
Example fix
// before
if (cddm.length !== 2 && cddm.length !== 4) {
throw new Error('cddm should be 2 or 4 digits');
}
// after (also enforce digits + name the param)
if (!/^\d{2}(\d{2})?$/.test(cddm)) {
throw new Error(`Invalid cddm '${cddm}': expected 2 or 4 digits`);
} Defensive patterns
Strategy: validation
Validate before calling
if (!/^\d{2}(\d{2})?$/.test(cddm)) {
throw new Error(`Invalid cddm '${cddm}': expected 2 or 4 digits`);
} Type guard
const isBuaaCddm = (c: string): boolean => /^\d{2}(\d{2})?$/.test(c); Prevention
- Document the 2-digit fcd / 4-digit cddm convention with concrete examples.
- Prefer a digit-enforcing regex over a bare length check to catch non-numeric input.
- Extract cddm values from the CMS page's onclick handlers exactly.
When it happens
Trigger: A request where cddm (after defaulting to '02') has a length other than 2 or 4 — e.g. '2', '020', '02035', or a non-numeric value whose string length is 3 or 5+.
Common situations: Passing a 1-digit code; passing a 5-digit code; copying only part of the onclick code from the CMS page; including whitespace/special characters.
Related errors
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/a484e7aeb935737f.
Report an issue: GitHub.