{"record":{"id":"f9c322a1de41d7c9","repo":"DIYgod/RSSHub","slug":"invalid-cycle-cycle-f9c322","errorCode":null,"errorMessage":"Invalid cycle: ${cycle}","messagePattern":"Invalid cycle: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"info","filePath":"lib/routes/huggingface/models.ts","lineNumber":46,"sourceCode":"    },\n    radar: [\n        {\n            source: ['huggingface.co/:group/models'],\n            target: '/models/:group',\n        },\n    ],\n    name: 'Group Models',\n    maintainers: ['WuNein'],\n    handler,\n    url: 'huggingface.co',\n};\n\nasync function handler(ctx) {\n    const { group, cycle = 'date' } = ctx.req.param();\n\n    // Validate cycle parameter\n    if (!['date', 'week', 'month'].includes(cycle)) {\n        throw new Error(`Invalid cycle: ${cycle}`);\n    }\n\n    const url = `https://huggingface.co/${group}/models?sort=created`;\n\n    const { body: response } = await got(url);\n    const $ = load(response);\n\n    let items = $('article')\n        .toArray()\n        .map((article) => {\n            const $article = $(article);\n            const title = $article.find('a > div > header > h4').text().trim();\n            const link = `https://huggingface.co/${title}`;\n            const timeElement = $article.find('a > div > div > span.truncate > time');\n            const datetime = timeElement.attr('datetime');\n            const description = $article.text().replaceAll(/\\s+/g, ' ').trim();\n\n            return {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/huggingface/models.ts#L28-L64","documentation":"Thrown by the Hugging Face Group Models route when the `cycle` value destructured from `ctx.req.param()` is not `date`, `week`, or `month`. Critically, the route path is `/models/:group` — there is no `:cycle` path parameter defined. Therefore `ctx.req.param('cycle')` always returns `undefined`, the destructuring default kicks in (`cycle = 'date'`), and this error is effectively unreachable through normal HTTP requests. It can only trigger if the handler is called directly with a bad cycle value.","triggerScenarios":"In normal RSSHub usage, this error cannot be triggered because `cycle` is not a path parameter. It would only fire if someone modified the route path to include `:cycle` or called the handler programmatically with an explicit cycle argument.","commonSituations":"A developer modifying this route to add cycle support (e.g. changing the path to `/models/:group/:cycle?`) without updating the validation, or code reading that expects cycle filtering that isn't wired to the URL.","solutions":["This error is dead code in the current route configuration — no action needed for end users.","If adding cycle support: update the route path to `/models/:group/:cycle?`, ensure the URL construction at line 49 actually uses the cycle value (currently it does not), and switch to `InvalidParameterError` for consistency.","If cycle support is not intended: remove the dead validation block (lines 44–47) to reduce confusion."],"exampleFix":"// before (dead code — cycle is not a path param)\nconst { group, cycle = 'date' } = ctx.req.param();\nif (!['date', 'week', 'month'].includes(cycle)) {\n    throw new Error(`Invalid cycle: ${cycle}`);\n}\nconst url = `https://huggingface.co/${group}/models?sort=created`;\n\n// after (remove dead validation, or wire cycle into the URL if intended)\nconst { group } = ctx.req.param();\nconst url = `https://huggingface.co/${group}/models?sort=created`;","handlingStrategy":"validation","validationCode":"// NOTE: cycle is not a path parameter in the current route definition.\n// This validation is unreachable in production. If cycle support is added:\nconst VALID_CYCLES = ['date', 'week', 'month'] as const;\nfunction isValidCycle(cycle: string): cycle is typeof VALID_CYCLES[number] {\n    return (VALID_CYCLES as readonly string[]).includes(cycle);\n}","typeGuard":"function isValidModelsCycle(cycle: string): cycle is 'date' | 'week' | 'month' {\n    return ['date', 'week', 'month'].includes(cycle);\n}","tryCatchPattern":null,"preventionTips":["Remove dead validation code that can never execute via normal HTTP requests.","If adding cycle support, update the route path AND wire the cycle value into the URL construction (currently the URL ignores cycle).","Use `InvalidParameterError` for parameter validation consistency."],"tags":["parameter-validation","dead-code","rsshub","programming"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}