DIYgod/RSSHub · error · Error

Invalid category: ${category}

Error message

Invalid category: ${category}

What it means

Thrown by the Le Monde route handler when the `:category` path parameter does not match any key in the static `feedMap` object (lib/routes/lemonde/index.ts:10). The handler resolves the category to an RSS XML URL via a dictionary lookup; an unknown slug yields `feedUrl === undefined`, so it aborts before any network call. Valid keys are the slugs listed in the route description (e.g. `international`, `politique`, `economie`, `societe`, `culture`, `sport`, `planete`, `pixels`, `sciences`, `idees`, `sante`, `em`, `en-continu`, `decodeurs`, or empty for the homepage).

Source

Thrown at lib/routes/lemonde/index.ts:80

| societe       | Society                |
| culture       | Culture                |
| sport         | Sports                 |
| planete       | Environment            |
| pixels        | Tech / Digital         |
| sciences      | Sciences               |
| idees         | Opinions               |
| sante         | Health                 |
| em            | M le mag               |
| en-continu    | Live / Breaking        |
| decodeurs     | Fact-checking          |`,
};

async function handler(ctx) {
    const category = ctx.req.param('category') ?? '';
    const feedUrl = feedMap[category];

    if (!feedUrl) {
        throw new Error(`Invalid category: ${category}`);
    }

    const xml = await ofetch(feedUrl);
    const $ = load(xml, { xml: true });

    const channel = $('channel');
    const feedTitle = channel.children('title').text();
    const feedLink = channel.children('link').text() || ROOT_URL;

    const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20;

    const items = $('item')
        .toArray()
        .slice(0, limit)
        .map((el) => {
            const item = $(el);
            const link = item.children('link').text() || item.children('guid').text();
            const title = item.children('title').text();

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the documented slugs from the route table (e.g. `/lemonde/international`, `/lemonde/sport`) or omit the category for the homepage feed.
  2. If you need a new section, add its slug and RSS URL to the `feedMap` dictionary in lib/routes/lemonde/index.ts:10 and rebuild.
  3. Verify the spelling and case — keys are lowercase and use hyphens (e.g. `en-continu`, not `EnContinu`).

Example fix

// before: GET /lemonde/world  -> throws
// after:  GET /lemonde/international
Defensive patterns

Strategy: validation

Validate before calling

const LEMONDE_CATEGORIES = ['', 'international', 'politique', 'economie', 'societe', 'culture', 'sport', 'planete', 'pixels', 'sciences', 'idees', 'sante', 'em', 'en-continu', 'decodeurs'];
function isValidLeMondeCategory(category: string): boolean {
    return LEMONDE_CATEGORIES.includes(category);
}
// before requesting: if (!isValidLeMondeCategory(slug)) return badRequest();

Type guard

function isLeMondeCategory(value: string): value is '' | 'international' | 'politique' | 'economie' | 'societe' | 'culture' | 'sport' | 'planete' | 'pixels' | 'sciences' | 'idees' | 'sante' | 'em' | 'en-continu' | 'decodeurs' {
    return value === '' || LEMONDE_CATEGORIES.includes(value);
}

Try / catch

// Match the dynamic message shape; surface a clean 400 to the caller.
try {
    await fetchRSS('/lemonde/' + slug);
} catch (e) {
    if (e instanceof Error && /^Invalid category:/.test(e.message)) {
        throw new TypeError(`Unknown Le Monde category '${slug}'`);
    }
    throw e;
}

Prevention

When it happens

Trigger: Requesting `/lemonde/<slug>` where `<slug>` is misspelled, uppercase, or not in `feedMap` — e.g. `/lemonde/world`, `/lemonde/Politics`, `/lemonde/economy`. Also triggered when the radar rule rewrites a source URL whose path segment is not a known slug.

Common situations: Users guessing English category names instead of the French slugs; copy-paste of a URL path that includes a trailing segment the map does not cover; radar auto-derivation from `lemonde.fr/<section>` where `<section>` is an article or non-feed section.

Related errors


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