DIYgod/RSSHub · error

Unknown type: ${item.type}

Error message

Unknown type: ${item.type}

What it means

Thrown from the item-type switch in the Zhihu xhu collection route. The switch maps `item.type` values (`article`, `answer`, `zvideo`, `pin`, etc.) to feed entries; any type not covered hits `default` and throws with the unknown type, so a single unsupported collected item aborts the whole collection feed.

Source

Thrown at lib/routes/zhihu/xhu/collection.ts:88

                    description = item.excerpt;

                    break;

                case 'answer':
                    title = item.question.title;
                    description = item.excerpt;

                    break;

                case 'pin': {
                    const pinItem = generateData([item])[0];
                    title = pinItem.title;
                    description = pinItem.description;

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

            return {
                title: `收藏了内容:${title}`,
                description,
                author,
                pubDate,
                guid: link,
                link,
            };
        }),
    };
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Add a `case` for the reported `item.type` that maps it to a feed entry (title/link/description), reusing the existing per-type helpers (e.g. `generateData`).
  2. Make `default` skip the item (`continue`/filter it out) instead of throwing so unsupported entries don't break the rest of the collection.
  3. Filter the items array by known types before the switch as a defensive pre-pass.

Example fix

// before
default:
    throw new Error(`Unknown type: ${item.type}`);
// after — skip unsupported collected items
default:
    return null;
Defensive patterns

Strategy: type-guard

Validate before calling

const HANDLED_COLLECTION_TYPES = new Set(['article', 'answer', 'zvideo', 'pin']);
function filterCollectionItems(items) {
    return items.filter((item) => HANDLED_COLLECTION_TYPES.has(item.type));
}

Type guard

type HandledCollectionType = 'article' | 'answer' | 'zvideo' | 'pin';
function isHandledCollectionType(item: { type: string }): item is { type: HandledCollectionType } {
    return new Set<HandledCollectionType>(['article','answer','zvideo','pin']).has(item.type as HandledCollectionType);
}

Try / catch

// Filter unknown types out before building the feed
const items = rawItems.filter(isHandledCollectionType).map(/* existing mapping */);

Prevention

When it happens

Trigger: A user's Zhihu collection contains an item of a type the route does not handle — e.g. a collected `question`, `topic`, `column`, or a new content kind the mirror starts exposing. The `default` arm then throws.

Common situations: Zhihu/xhu mirror adds a new collectible content type; the collection mixes types (articles + a question) and the unhandled one trips the switch; the mirror renames a type string. The unhandled item poisons the entire feed.

Related errors


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