{"record":{"id":"edaa956d9e614d17","repo":"siyuan-note/siyuan","slug":"empty-iframe-block","errorCode":null,"errorMessage":"empty IFrame block","messagePattern":"empty IFrame block","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/tools/asset.go","lineNumber":189,"sourceCode":"\t\tname = \"component.html\"\n\t}\n\tname = filepath.Base(name)\n\text := strings.ToLower(filepath.Ext(name))\n\tif ext != \".html\" && ext != \".htm\" {\n\t\treturn \"\", fmt.Errorf(\"name must end in .html or .htm\")\n\t}\n\treturn name, nil\n}\n\nfunc htmlAssetIFrameBlockDOM(assetPath string) (dom, blockID string, err error) {\n\tsrc := html.EscapeString(model.HTMLAssetIFrameSrc(assetPath))\n\tdom, err = markdownToBlockDOM(`<iframe sandbox=\"allow-scripts\" src=\"` + src + `\" border=\"0\" frameborder=\"no\" framespacing=\"0\" allowfullscreen=\"true\"></iframe>`)\n\tif err != nil {\n\t\treturn\n\t}\n\ttree := util.NewLute().BlockDOM2Tree(dom)\n\tif tree == nil || tree.Root == nil || tree.Root.FirstChild == nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"empty IFrame block\")\n\t}\n\tblockID = tree.Root.FirstChild.ID\n\treturn\n}\n\nfunc newAssetUploadToolResult(succeeded []model.AssetUploadSuccess, failed []model.AssetUploadFailure) CallToolResult {\n\tvar sb strings.Builder\n\tsb.WriteString(fmt.Sprintf(\"Uploaded %d file(s):\\n\", len(succeeded)))\n\tfor _, result := range succeeded {\n\t\tsb.WriteString(fmt.Sprintf(\"- %s -> %s\\n\", result.Name, result.Path))\n\t}\n\tif 0 < len(failed) {\n\t\tsb.WriteString(fmt.Sprintf(\"\\nFailed %d file(s):\\n\", len(failed)))\n\t\tfor _, result := range failed {\n\t\t\tsb.WriteString(fmt.Sprintf(\"- %s: %s\\n\", result.Name, result.Error))\n\t\t}\n\t}\n\treturn CallToolResult{Content: []ContentItem{{Type: \"text\", Text: sb.String()}}, IsError: 0 < len(failed)}","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/tools/asset.go#L171-L207","documentation":"htmlAssetIFrameBlockDOM renders a sandboxed iframe snippet to a block DOM tree via Lute (markdownToBlockDOM then BlockDOM2Tree) and requires the resulting tree to contain at least one node under Root. An empty tree/nil root means the parser produced no block for the iframe markup, so no block ID can be extracted.","triggerScenarios":"markdownToBlockDOM fails or returns markup that BlockDOM2Tree parses into a tree with nil Root or no FirstChild — typically a Lute rendering failure or version mismatch for raw HTML/iframe blocks, surfaced through assetCreateHTML.","commonSituations":"A Lute (lute.min.js / Go lute) version where iframe HTML is stripped or parsed differently; corrupted or uninitialized Lute instance in tests; markdown pipeline changes dropping raw HTML blocks.","solutions":["Verify the Go lute library and lute.min.js are current and in sync so iframe HTML blocks parse into a tree","Log the dom string returned by markdownToBlockDOM before parsing to see whether the renderer produced empty output","Check the error returned by markdownToBlockDOM first — a rendering failure upstream is the usual root cause","Add a regression test rendering a minimal iframe to catch Lute behavior changes"],"exampleFix":"// before\ndom, err := markdownToBlockDOM(iframeMarkdown) // err ignored upstream, empty dom\n// after\nif dom == \"\" || err != nil {\n    return \"\", \"\", fmt.Errorf(\"markdown render failed: %w\", err)\n}\ntree := util.NewLute().BlockDOM2Tree(dom)","handlingStrategy":"try-catch","validationCode":"tree := util.NewLute().BlockDOM2Tree(dom)\nif tree == nil || tree.Root == nil || tree.Root.FirstChild == nil {\n    return fmt.Errorf(\"lute produced an empty tree for iframe dom\")\n}","typeGuard":null,"tryCatchPattern":"blockID, _, err := htmlAssetIFrameBlockDOM()\nif err != nil && strings.Contains(err.Error(), \"empty IFrame block\") {\n    // check Lute version / markdown renderer output before retry\n}","preventionTips":["Keep Go lute and lute.min.js versions in sync","Check the markdownToBlockDOM error and output before tree conversion","Add a minimal iframe rendering regression test"],"tags":["lute","dom","parsing"],"backgroundTag":"empty-result-set","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}