DIYgod/RSSHub · warning · Error

Invalid category: ${category}

Error message

Invalid category: ${category}

What it means

Thrown by the lemonde (Le Monde English) handler as a plain Error when the `category` path param is not a key in feedMap. feedMap maps slugs (international, economy, sports, opinion, etc., plus '' for the homepage) to RSS XML URLs. An unknown slug yields feedUrl=undefined, which the guard rejects before any fetch.

Source

Thrown at lib/routes/lemonde/en.ts:159

| science                 | Science                   |
| health                  | Health                    |
| intimacy                | Intimacy                  |
| les-decodeurs           | Les Décodeurs             |
| our-times               | Our Times                 |
| obituaries              | Obituaries                |
| religion                | Religion                  |
| opinion                 | Opinion                   |
| editorials              | Opinion – Editorials      |
| columns                 | Opinion – Columns         |
| op-eds                  | Opinion – Op-Eds          |`,
};

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 a slug from the route description table (e.g. international, economy, sports, opinion)
  2. Omit the segment to get the homepage feed
  3. If Le Monde added a new RSS feed, add the slug→URL mapping to feedMap in lib/routes/lemonde/en.ts:10-72
  4. Watch for hyphenated slugs (asia-pacific, united-states) — exact match required

Example fix

// before
const feedUrl = feedMap[category];
if (!feedUrl) {
    throw new Error(`Invalid category: ${category}`);
}
// after — list valid keys on failure
const feedUrl = feedMap[category];
if (!feedUrl) {
    const valid = Object.keys(feedMap).map((k) => k || '(empty)').join(', ');
    throw new Error(`Invalid category '${category}'. Valid: ${valid}`);
}
Defensive patterns

Strategy: type-guard

Validate before calling

const FEED_MAP_KEYS = new Set(Object.keys(feedMap));
function isValidLeMondeCategory(cat: string): boolean {
  return FEED_MAP_KEYS.has(cat);
}
if (!isValidLeMondeCategory(ctx.req.param('category') ?? '')) {
  return ctx.json({ error: `invalid category`, allowed: [...FEED_MAP_KEYS] }, 400);
}

Type guard

function isLeMondeCategory(v: unknown): v is keyof typeof feedMap {
  return typeof v === 'string' && v in feedMap;
}

Try / catch

try { return await handler(ctx); }
catch (e) {
  if (e instanceof Error && /Invalid category/.test(e.message)) {
    return ctx.json({ error: e.message, valid: Object.keys(feedMap) }, 400);
  }
  throw e;
}

Prevention

When it happens

Trigger: Request to /lemonde/en/<slug> where <slug> is not in feedMap — e.g. /lemonde/en/world (wrong; should be 'international'), /lemonde/en/politique (French slug; English edition uses 'politics'), or a typo. Omitting the category is safe (defaults to '' = homepage).

Common situations: User uses a French-edition or Le Monde.fr slug instead of the English-edition one; typo; trailing slash creating an empty-but-present segment; slug was removed from Le Monde's RSS offering.

Related errors


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