DIYgod/RSSHub · error · InvalidParameterError

Unknown region: ${region}

Error message

Unknown region: ${region}

What it means

InvalidParameterError thrown by the Yahoo news provider handler when ctx.req.param('region') is not 'hk' or 'tw'. This route filters a region's archive by a specific providerId (e.g. yahoo_movies_hk_660), which is a HK/TW-only concept, so other regions are rejected before getProviderList/getArchive run.

Source

Thrown at lib/routes/yahoo/news/provider.ts:46

    maintainers: ['TonyRL', 'williamgateszhao'],
    handler,
    description: `\`Region\`

| 香港 | 台灣 |
| ---- | ---- |
| hk   | tw   |

\`ProviderId\`

除了可以通过路由 "新聞來源列表" 获得外,也可通过 hk.news.yahoo.com/archive 和 tw\\.news.yahoo.com/archive 选择 "新闻来源" 后通过页面 Url 来获得。

例如 hk.news.yahoo.com/yahoo\\_movies\\_hk\\_660-- 所有分類 /archive, \`yahoo_movies_hk_660\` 就是 ProviderId 。`,
};

async function handler(ctx) {
    const { region, providerId } = ctx.req.param();
    if (!['hk', 'tw'].includes(region)) {
        throw new InvalidParameterError(`Unknown region: ${region}`);
    }

    const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20;
    const providerList = await getProviderList(region);
    const provider = providerList.find((p) => p.key === providerId);

    const response = await getArchive(region, limit, [], providerId);
    const list = parseList(region, response);

    const items = await Promise.all(list.map((item) => parseItem(item)));

    return {
        title: `Yahoo 新聞 - ${provider?.title ?? ''}`,
        link: provider?.link ?? `https://${region}.news.yahoo.com`,
        image: 'https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo-1200x1200.png',
        item: items,
    };
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Use 'hk' or 'tw' as the region segment.
  2. Obtain a valid providerId from the provider-helper route (/yahoo/news/provider-list/hk) or from the archive page URL on hk/tw.news.yahoo.com.
Defensive patterns

Strategy: validation

Validate before calling

function requireHkTwRegion(region: string) {
    if (!['hk', 'tw'].includes(region)) {
        throw new InvalidParameterError(`Unknown region: ${region}. Use hk or tw.`);
    }
}

Type guard

function isHkTwRegion(value: string): value is 'hk' | 'tw' {
    return value === 'hk' || value === 'tw';
}

Prevention

When it happens

Trigger: A request to /yahoo/news/provider/:region/:providerId with region outside hk/tw. The guard fires immediately after destructuring {region, providerId}.

Common situations: Caller used a US/other region with a providerId; assumed the provider concept is global; typo.

Related errors


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