{"record":{"id":"81d429526909526f","repo":"DIYgod/RSSHub","slug":"invalid-cycle-cycle","errorCode":null,"errorMessage":"Invalid cycle: ${cycle}","messagePattern":"Invalid cycle: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/routes/huggingface/daily-papers.ts","lineNumber":64,"sourceCode":"    dailyPapers: DailyPaperItem[];\n}\n\nasync function handler(ctx) {\n    const { cycle = 'date', voteFliter = '0' } = ctx.req.param();\n    let url: string;\n    switch (cycle) {\n        case 'date':\n            url = 'https://huggingface.co/papers';\n            break;\n        case 'week':\n            // We don't actually need to get the week number, because huggingface.co/papers/week/YYYY-W52 will redirect to the latest week\n            url = `https://huggingface.co/papers/week/${new Date().getFullYear()}-W52`;\n            break;\n        case 'month':\n            url = `https://huggingface.co/papers/month/${new Date().toISOString().slice(0, 7)}`;\n            break;\n        default:\n            throw new Error(`Invalid cycle: ${cycle}`);\n    }\n\n    const { body: response } = await got(url);\n    const $ = load(response);\n    const papers = $('div[data-target=\"DailyPapers\"]').data('props') as PapersData;\n\n    const items = papers.dailyPapers\n        .filter((item) => item.paper.upvotes >= voteFliter)\n        .map((item) => ({\n            title: item.title,\n            link: `https://arxiv.org/abs/${item.paper.id}`,\n            description: item.paper.summary.replaceAll('\\n', ' '),\n            pubDate: parseDate(item.publishedAt),\n            author: item.paper.authors.map((author) => author.name).join(', '),\n            upvotes: item.paper.upvotes,\n        }))\n        .toSorted((a, b) => b.upvotes - a.upvotes);\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/huggingface/daily-papers.ts#L46-L82","documentation":"Thrown by the Hugging Face Daily Papers route when the `:cycle` path parameter is not one of `date`, `week`, or `month`. The handler uses a `switch` statement with a `default` branch that throws a plain `Error` (not `InvalidParameterError`, which is inconsistent with RSSHub conventions). The cycle determines which Hugging Face papers URL is fetched.","triggerScenarios":"Requesting `/huggingface/daily-papers/<cycle>/...` where `<cycle>` is not `date`, `week`, or `month`. The parameter defaults to `date` when omitted, so omitting it is safe.","commonSituations":"Typo in the cycle value, using an unsupported value like `year` or `daily`, or passing an empty string explicitly.","solutions":["Use `date`, `week`, or `month` — or omit the parameter entirely (defaults to `date`).","As a maintainer: change `throw new Error(...)` to `throw new InvalidParameterError(...)` for consistent HTTP 400 behavior."],"exampleFix":"// before (broken)\n// GET /huggingface/daily-papers/yearly/50\n\n// after (correct)\n// GET /huggingface/daily-papers/week/50","handlingStrategy":"validation","validationCode":"const 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 isValidPapersCycle(cycle: string): cycle is 'date' | 'week' | 'month' {\n    return ['date', 'week', 'month'].includes(cycle);\n}","tryCatchPattern":null,"preventionTips":["Use `InvalidParameterError` instead of plain `Error` for consistent HTTP 400 behavior.","Omit the cycle parameter to default to `date`.","Document the three valid values in the route parameters description."],"tags":["parameter-validation","rsshub","programming"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}