{"record":{"id":"a484e7aeb935737f","repo":"DIYgod/RSSHub","slug":"cddm-should-be-2-or-4-digits","errorCode":null,"errorMessage":"cddm should be 2 or 4 digits","messagePattern":"cddm should be 2 or 4 digits","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/routes/buaa/jiaowu.ts","lineNumber":49,"sourceCode":"    categories: ['university'],\n    features: {\n        requireConfig: false,\n        requirePuppeteer: false,\n        antiCrawler: false,\n        supportRadar: false,\n        supportBT: false,\n        supportPodcast: false,\n        supportScihub: false,\n    },\n};\n\nasync function handler(ctx: Context): Promise<Data> {\n    let cddm = ctx.req.param('cddm');\n    if (!cddm) {\n        cddm = '02';\n    }\n    if (cddm.length !== 2 && cddm.length !== 4) {\n        throw new Error('cddm should be 2 or 4 digits');\n    }\n\n    const { title, list } = await getList(BASE_URL, {\n        id: '',\n        fcdTab: cddm.slice(0, 2),\n        cddmTab: cddm,\n        xsfsTab: '2',\n        tplbid: '',\n        xwid: '',\n        zydm: '',\n        zymc: '',\n        yxdm: '',\n        pyzy: '',\n        szzqdm: '',\n    });\n    const item = await getItems(list);\n\n    return {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/buaa/jiaowu.ts#L31-L67","documentation":"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.","triggerScenarios":"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+.","commonSituations":"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.","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)."],"exampleFix":"// before\nif (cddm.length !== 2 && cddm.length !== 4) {\n    throw new Error('cddm should be 2 or 4 digits');\n}\n// after (also enforce digits + name the param)\nif (!/^\\d{2}(\\d{2})?$/.test(cddm)) {\n    throw new Error(`Invalid cddm '${cddm}': expected 2 or 4 digits`);\n}","handlingStrategy":"validation","validationCode":"if (!/^\\d{2}(\\d{2})?$/.test(cddm)) {\n    throw new Error(`Invalid cddm '${cddm}': expected 2 or 4 digits`);\n}","typeGuard":"const isBuaaCddm = (c: string): boolean => /^\\d{2}(\\d{2})?$/.test(c);","tryCatchPattern":null,"preventionTips":["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."],"tags":["buaa","validation","path-parameter","length-check"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}