DIYgod/RSSHub · error · Error

Unknown type: ${type}

Error message

Unknown type: ${type}

What it means

Generic Error from the default branch of the BSE (Beijing Stock Exchange) switch on `type`, where `type` is read from the internal `nodes` config table (nodes[category].type), not directly from user input. Reaching the default means a category in the nodes table was configured with a type value the switch does not handle — an internal invariant violation rather than a user typo.

Source

Thrown at lib/routes/bse/index.ts:210

            items = data.data.content.map((item) => ({
                title: item.title,
                category: item.tags,
                description: item.text,
                link: `${rootUrl}${item.htmlUrl}`,
                pubDate: timezone(parseDate(item.publishDate), 8),
            }));
            break;

        case '/disclosureInfoController/zoneInfoResult':
            items = data.listInfo.content.map((item) => ({
                title: item.disclosureTitle,
                link: `${rootUrl}${item.destFilePath}`,
                pubDate: parseDate(item.pubDate.time),
            }));
            break;

        default:
            throw new Error(`Unknown type: ${type}`);
    }

    return {
        title: `${nodes[category].title} - 北京证券交易所`,
        link: `${rootUrl}${nodes[category].url}`,
        item: items,
        allowEmpty: true,
    };
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Add a switch case for the new type slug returned in the message (e.g. case '/someNewType': items = ...; break;).
  2. Or correct the nodes[category].type value to one of the two handled slugs if it was mistyped.
  3. Add a static check/test that every nodes[*].type has a corresponding switch case to catch this at build time.

Example fix

// before
default:
    throw new Error(`Unknown type: ${type}`);
// after (also validate category against nodes earlier so the message is actionable)
if (!nodes[category]) {
    throw new Error(`Unknown category: ${category}`);
}
// ... and ensure every nodes[*].type has a switch case
Defensive patterns

Strategy: validation

Validate before calling

// Validate category against nodes first, and assert every nodes type is handled:
if (!nodes[category]) throw new Error(`Unknown category: ${category}`);
const type = nodes[category].type;
const HANDLED = new Set(['/info/listse','/disclosureInfoController/zoneInfoResult']);
if (!HANDLED.has(type)) throw new Error(`Unknown type: ${type}`);

Type guard

const HANDLED_TYPES = new Set(['/info/listse','/disclosureInfoController/zoneInfoResult']);
const isHandledType = (t: string): boolean => HANDLED_TYPES.has(t);

Prevention

When it happens

Trigger: A category whose nodes entry has `.type` set to something other than '/info/listse' or '/disclosureInfoController/zoneInfoResult'. This happens when a maintainer adds a node entry with a new type slug but forgets to add the matching switch case.

Common situations: Maintainer edits the nodes table and adds a third type without extending the switch; a refactor renames a type slug in nodes but not in the switch; copy-paste of a node entry with an unhandled type.

Related errors


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