{"record":{"id":"3e16f0256a27a8c9","repo":"DIYgod/RSSHub","slug":"unknown-handled-type-element-type-json-stri","errorCode":null,"errorMessage":"Unknown handled type: ${element.type}, ${JSON.stringify(element)}","messagePattern":"Unknown handled type: (.+?), (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/gocn/utils.ts","lineNumber":31,"sourceCode":"    p: (element) => `<p>${renderHTML(element.children)}</p>`,\n    strong: (element) => `<strong>${renderHTML(element.children)}</strong>`,\n    ol: (element) => `<ol>${renderHTML(element.children)}</ol>`,\n    ul: (element) => `<ul>${renderHTML(element.children)}</ul>`,\n    li: (element) => `<li>${renderHTML(element.children)}</li>`,\n    lic: (element) => element.children[0].text,\n};\n\nfunction renderHTML(json) {\n    return json\n        .map((element) => {\n            const handler = elementMap[element.type];\n            if (handler) {\n                return handler(element);\n            }\n            if (Object.hasOwn(element, 'text')) {\n                return element.text;\n            }\n            throw new Error(`Unknown handled type: ${element.type}, ${JSON.stringify(element)}`);\n        })\n        .join('');\n}\n\nexport { renderHTML };\n","sourceCodeStart":13,"sourceCodeEnd":37,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/gocn/utils.ts#L13-L37","documentation":"Thrown by the GoCN renderHTML utility when processing a JSON document representing rich text content. Each element is looked up in the elementMap (code_block, a, blockquote, br, h1-h6, img, p, strong, ol, ul, li, lic). If no handler exists AND the element has no 'text' property as a fallback, this error fires with the full JSON of the unrecognized element.","triggerScenarios":"The GoCN API returns a JSON content tree containing an element with a 'type' value not present in the elementMap (e.g., 'table', 'hr', 'em', 'italic', 'inline_code') and the element does not have a top-level 'text' property. This is reached during renderHTML(json) which maps over every element in the array.","commonSituations":"The upstream content source (GoCN) added a new rich-text element type (e.g., tables, horizontal rules, inline formatting); the content includes nested structures that the flat elementMap doesn't cover; a schema version change introduced new element types.","solutions":["Inspect the element JSON in the error message to identify the new type","Add a handler for the new type to the elementMap object in utils.ts","As a temporary fix, add the new type to a fallback that extracts text or returns an empty string","If the element is decorative (e.g., 'hr'), add a simple handler like hr: () => '<hr>'"],"exampleFix":"// before (only catches, then throws)\nif (Object.hasOwn(element, 'text')) {\n    return element.text;\n}\nthrow new Error(`Unknown handled type: ${element.type}, ${JSON.stringify(element)}`);\n\n// after (add new handlers + graceful fallback)\n// 1. Add to elementMap:\n//    hr: () => '<hr>',\n//    em: (element) => `<em>${renderHTML(element.children)}</em>`,\n//    table: (element) => `<table>${renderHTML(element.children)}</table>`,\n// 2. Use a non-throwing fallback:\n//    return element.text || '';  // instead of throwing","handlingStrategy":"type-guard","validationCode":"// Validate element types before rendering\nconst KNOWN_TYPES = new Set([...Object.keys(elementMap), 'text']);\nfunction validateElements(json: any[]): void {\n    for (const el of json) {\n        if (!KNOWN_TYPES.has(el.type) && !Object.hasOwn(el, 'text')) {\n            console.warn(`Unknown element type: ${el.type}`, el);\n        }\n        if (el.children && Array.isArray(el.children)) {\n            validateElements(el.children);\n        }\n    }\n}","typeGuard":"function isKnownElement(element: unknown): boolean {\n    if (typeof element !== 'object' || element === null) return false;\n    const el = element as Record<string, unknown>;\n    return Object.hasOwn(elementMap, el.type as string) || Object.hasOwn(el, 'text');\n}","tryCatchPattern":null,"preventionTips":["Add new element types to elementMap proactively when the upstream schema changes","Use a non-throwing fallback (return element.text || '') for unknown types in production","Log unknown types for investigation instead of crashing the entire feed","Write tests that cover diverse content tree shapes"],"tags":["scraper","json-parsing","schema-change","third-party-api","extensibility"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}