DIYgod/RSSHub · info · Error

Invalid cycle: ${cycle}

Error message

Invalid cycle: ${cycle}

What it means

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.

Source

Thrown at lib/routes/huggingface/models.ts:46

    },
    radar: [
        {
            source: ['huggingface.co/:group/models'],
            target: '/models/:group',
        },
    ],
    name: 'Group Models',
    maintainers: ['WuNein'],
    handler,
    url: 'huggingface.co',
};

async function handler(ctx) {
    const { group, cycle = 'date' } = ctx.req.param();

    // Validate cycle parameter
    if (!['date', 'week', 'month'].includes(cycle)) {
        throw new Error(`Invalid cycle: ${cycle}`);
    }

    const url = `https://huggingface.co/${group}/models?sort=created`;

    const { body: response } = await got(url);
    const $ = load(response);

    let items = $('article')
        .toArray()
        .map((article) => {
            const $article = $(article);
            const title = $article.find('a > div > header > h4').text().trim();
            const link = `https://huggingface.co/${title}`;
            const timeElement = $article.find('a > div > div > span.truncate > time');
            const datetime = timeElement.attr('datetime');
            const description = $article.text().replaceAll(/\s+/g, ' ').trim();

            return {

View on GitHub (pinned to bed535e087)

Solutions

  1. This error is dead code in the current route configuration — no action needed for end users.
  2. 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.
  3. If cycle support is not intended: remove the dead validation block (lines 44–47) to reduce confusion.

Example fix

// before (dead code — cycle is not a path param)
const { group, cycle = 'date' } = ctx.req.param();
if (!['date', 'week', 'month'].includes(cycle)) {
    throw new Error(`Invalid cycle: ${cycle}`);
}
const url = `https://huggingface.co/${group}/models?sort=created`;

// after (remove dead validation, or wire cycle into the URL if intended)
const { group } = ctx.req.param();
const url = `https://huggingface.co/${group}/models?sort=created`;
Defensive patterns

Strategy: validation

Validate before calling

// NOTE: cycle is not a path parameter in the current route definition.
// This validation is unreachable in production. If cycle support is added:
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 isValidModelsCycle(cycle: string): cycle is 'date' | 'week' | 'month' {
    return ['date', 'week', 'month'].includes(cycle);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/f9c322a1de41d7c9. Report an issue: GitHub.