DIYgod/RSSHub · warning · Error
Invalid cycle: ${cycle}
Error message
Invalid cycle: ${cycle} What it means
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.
Source
Thrown at lib/routes/huggingface/daily-papers.ts:64
dailyPapers: DailyPaperItem[];
}
async function handler(ctx) {
const { cycle = 'date', voteFliter = '0' } = ctx.req.param();
let url: string;
switch (cycle) {
case 'date':
url = 'https://huggingface.co/papers';
break;
case 'week':
// We don't actually need to get the week number, because huggingface.co/papers/week/YYYY-W52 will redirect to the latest week
url = `https://huggingface.co/papers/week/${new Date().getFullYear()}-W52`;
break;
case 'month':
url = `https://huggingface.co/papers/month/${new Date().toISOString().slice(0, 7)}`;
break;
default:
throw new Error(`Invalid cycle: ${cycle}`);
}
const { body: response } = await got(url);
const $ = load(response);
const papers = $('div[data-target="DailyPapers"]').data('props') as PapersData;
const items = papers.dailyPapers
.filter((item) => item.paper.upvotes >= voteFliter)
.map((item) => ({
title: item.title,
link: `https://arxiv.org/abs/${item.paper.id}`,
description: item.paper.summary.replaceAll('\n', ' '),
pubDate: parseDate(item.publishedAt),
author: item.paper.authors.map((author) => author.name).join(', '),
upvotes: item.paper.upvotes,
}))
.toSorted((a, b) => b.upvotes - a.upvotes);
View on GitHub (pinned to bed535e087)
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.
Example fix
// before (broken) // GET /huggingface/daily-papers/yearly/50 // after (correct) // GET /huggingface/daily-papers/week/50
Defensive patterns
Strategy: validation
Validate before calling
const VALID_CYCLES = ['date', 'week', 'month'] as const;
function isValidCycle(cycle: string): cycle is typeof VALID_CYCLES[number] {
return (VALID_CYCLES as readonly string[]).includes(cycle);
} Type guard
function isValidPapersCycle(cycle: string): cycle is 'date' | 'week' | 'month' {
return ['date', 'week', 'month'].includes(cycle);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Typo in the cycle value, using an unsupported value like `year` or `daily`, or passing an empty string explicitly.
Related errors
- Invalid cycle: ${cycle}
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Nanjing, Cannot find page
- Bad category. See <a href="https://docs.rsshub.app/routes/go
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/81d429526909526f.
Report an issue: GitHub.