DIYgod/RSSHub · warning · InvalidParameterError

Tag not found

Error message

Tag not found

What it means

Thrown by the baai hub route when a tagId is supplied but does not match any entry returned by getTagsData(). It uses InvalidParameterError so RSSHub surfaces a clear 400-style message instead of fetching an empty story list.

Source

Thrown at lib/routes/baai/hub.ts:61

    maintainers: ['TonyRL'],
    handler,
};

async function handler(ctx) {
    const { tagId = '', sort = 'new', range } = ctx.req.param();

    let title, description, brief, iconUrl;
    if (tagId) {
        const tagsData = await getTagsData();

        const tag = (tagsData as Array<Record<string, string>>).find((tag) => tag.id === tagId);
        if (tag) {
            title = tag.title;
            description = tag.description;
            brief = tag.brief;
            iconUrl = tag.iconUrl;
        } else {
            throw new InvalidParameterError('Tag not found');
        }
    }

    const response = await ofetch(`${apiHost}/api/v1/story/list`, {
        method: 'POST',
        query: {
            page: 1,
            sort,
            tag_id: tagId,
            time_range: range,
        },
    });

    const list = response.data.map((item) => parseItem(item));

    const items = await Promise.all(
        list.map((item) =>
            cache.tryGet(item.link, async () => {

View on GitHub (pinned to bed535e087)

Solutions

  1. Look up the current tag list via getTagsData (or the route's documented options) and use a valid tag id.
  2. If you want all stories, omit tagId so the validation block is skipped entirely.

Example fix

// before
const tag = (tagsData as Array<Record<string, string>>).find((tag) => tag.id === tagId);
if (tag) { /* ... */ } else {
    throw new InvalidParameterError('Tag not found');
}

// after: list valid ids in the error so the caller can self-correct
const tag = tagsData.find((t) => t.id === tagId);
if (!tag) {
    const valid = tagsData.map((t) => t.id).join(', ');
    throw new InvalidParameterError(`Tag not found: ${tagId}. Valid ids: ${valid}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const tagsData = await getTagsData();
const tag = tagsData.find((t) => t.id === tagId);
if (!tag) {
    throw new InvalidParameterError(`Tag not found: ${tagId}. Valid: ${tagsData.map((t) => t.id).join(', ')}`);
}

Type guard

function isKnownTagId(tagsData: Array<{ id: string }>, id: string): boolean {
    return tagsData.some((t) => t.id === id);
}

Prevention

When it happens

Trigger: Calling the route with a tagId path parameter whose value is not present in the tags dataset returned by getTagsData(); the find() returns undefined and the else branch throws.

Common situations: Stale tagId from old documentation; BAAI renames or removes a tag; user copies a numeric id that was never a tag.

Related errors


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