{"record":{"id":"4ccc8def83362515","repo":"BabylonJS/Babylon.js","slug":"was-asked-to-serialize-an-unrecognized-block-type","errorCode":null,"errorMessage":"Was asked to serialize an unrecognized block type","messagePattern":"Was asked to serialize an unrecognized block type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/smartFilters/src/blockFoundation/customShaderBlock.serializer.ts","lineNumber":27,"sourceCode":"    /**\r\n     * The custom properties of the CustomShaderBlock\r\n     */\r\n    customProperties: CustomPropertyData[];\r\n};\r\n\r\ntype CustomPropertyData = {\r\n    name: string;\r\n    value: any;\r\n};\r\n\r\n/**\r\n * Serializes a CustomShaderBlock to V1 serialized data.\r\n * @param block - The block to serialize\r\n * @returns The serialized block\r\n */\r\nexport const CustomShaderBlockSerializer: SerializeBlockV1 = (block: BaseBlock): ISerializedBlockV1 => {\r\n    if (block.getClassName() !== CustomShaderBlock.ClassName) {\r\n        throw new Error(\"Was asked to serialize an unrecognized block type\");\r\n    }\r\n    const customShaderBlock = block as CustomShaderBlock;\r\n\r\n    let data: CustomShaderBlockData | undefined;\r\n    const dynamicPropertyNames = customShaderBlock.dynamicPropertyNames;\r\n    if (dynamicPropertyNames.length > 0) {\r\n        data = {\r\n            customProperties: dynamicPropertyNames.map((propertyName) => ({\r\n                name: propertyName,\r\n                value: (customShaderBlock as any)[propertyName],\r\n            })),\r\n        };\r\n    }\r\n\r\n    return {\r\n        name: customShaderBlock.name,\r\n        uniqueId: customShaderBlock.uniqueId,\r\n        blockType: customShaderBlock.blockType,\r","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/smartFilters/src/blockFoundation/customShaderBlock.serializer.ts#L9-L45","documentation":"CustomShaderBlockSerializer only knows how to serialize blocks whose getClassName() equals CustomShaderBlock.ClassName. Passing any other BaseBlock is a caller bug, so the serializer throws rather than emitting wrong data.","triggerScenarios":"Registering CustomShaderBlockSerializer as a generic SerializeBlockV1 and invoking it with a block of a different class (e.g. an InputBlock or another custom block).","commonSituations":"A block-type-to-serializer registry mapping keyed incorrectly, iterating all filter blocks and applying one serializer to each, or a custom block that forgot to define its own serializer.","solutions":["Dispatch to the serializer matching block.getClassName() before calling CustomShaderBlockSerializer.","Register a dedicated serializer for every custom block class in your serializer map.","Add a default/fallback serializer path for unknown classes instead of routing them here.","Log block.getClassName() at the call site to identify the mismatched block."],"exampleFix":"// before\nconst serialized = CustomShaderBlockSerializer(block);\n// after\nconst serializer = serializers[block.getClassName()];\nif (!serializer) throw new Error(`No serializer for ${block.getClassName()}`);\nconst serialized = serializer(block);","handlingStrategy":"type-guard","validationCode":"if (block.getClassName() === CustomShaderBlock.ClassName) {\n    const serialized = CustomShaderBlockSerializer(block);\n}","typeGuard":"function isCustomShaderBlock(block: BaseBlock): block is CustomShaderBlock {\n    return block.getClassName() === CustomShaderBlock.ClassName;\n}","tryCatchPattern":"try {\n    return CustomShaderBlockSerializer(block);\n} catch (e) {\n    if (e instanceof Error && e.message.includes('unrecognized block type')) {\n        return serializers[block.getClassName()]?.(block) ?? fallbackSerializer(block);\n    }\n    throw e;\n}","preventionTips":["Look up serializers by getClassName() instead of hardcoding one serializer.","Register a serializer for every custom block class at startup.","Fail fast with the block class name in your own dispatch error message."],"tags":["smart-filters","serialization","type-mismatch"],"backgroundTag":"serializer-type-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}