{"record":{"id":"e5e576fa5c7104cd","repo":"siyuan-note/siyuan","slug":"query-embed-block-statement-not-found","errorCode":null,"errorMessage":"query embed block statement not found","messagePattern":"query embed block statement not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/search.go","lineNumber":312,"sourceCode":"\t}\n\tif treenode.TypeAbbr(ast.NodeBlockQueryEmbed.String()) != bt.Type {\n\t\terr = errors.New(\"not query embed block\")\n\t\treturn\n\t}\n\n\ttree, loadErr := filesys.LoadTree(bt.BoxID, bt.Path, util.NewLute())\n\tif nil != loadErr {\n\t\terr = loadErr\n\t\treturn\n\t}\n\tnode := treenode.GetNodeInTree(tree, embedBlockID)\n\tif nil == node || ast.NodeBlockQueryEmbed != node.Type {\n\t\terr = ErrBlockNotFound\n\t\treturn\n\t}\n\tscriptNode := node.ChildByType(ast.NodeBlockQueryEmbedScript)\n\tif nil == scriptNode {\n\t\terr = errors.New(\"query embed block statement not found\")\n\t\treturn\n\t}\n\n\tstmt = stdhtml.UnescapeString(scriptNode.TokensStr())\n\tstmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, \"\\n\")\n\tboxID = bt.BoxID\n\treturn\n}\n\nfunc SearchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMode int, breadcrumb bool) (ret []*EmbedBlock) {\n\treturn SearchEmbedBlockInBox(embedBlockID, stmt, excludeIDs, headingMode, breadcrumb, \"\")\n}\n\n// SearchEmbedBlockInBox 与 SearchEmbedBlock 一致，但按 boxID 路由 SQL 到加密 content db。\n// 加密笔记本的嵌入块查询走独立加密库（全局 siyuan.db 不含加密数据），boxID 为空时落回全局库。\nfunc SearchEmbedBlockInBox(embedBlockID, stmt string, excludeIDs []string, headingMode int, breadcrumb bool, boxID string) (ret []*EmbedBlock) {\n\treturn searchEmbedBlockInBox(embedBlockID, stmt, excludeIDs, headingMode, breadcrumb, boxID, true)\n}","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/search.go#L294-L330","documentation":"After loading the tree for a verified embed block, GetQueryEmbedStatement locates the node and then its child NodeBlockQueryEmbedScript holding the SQL statement. If the node is missing or the script child node is absent, the embed block is structurally malformed and the library errors with \"query embed block statement not found\". This indicates internal data corruption rather than a bad argument.","triggerScenarios":"Calling GetQueryEmbedStatement on an embed block whose tree contains a NodeBlockQueryEmbed node but no NodeBlockQueryEmbedScript child — e.g. the .sy file was hand-edited, truncated, or produced by a version that serialized the embed node without its script child.","commonSituations":"Documents edited by older/custom tooling or third-party sync that wrote malformed embed nodes; partially-written .sy files after a crash; manual XML editing of the .sy file that dropped the script child.","solutions":["Re-open the embed block in the editor and re-enter the SQL statement so the script child node is rewritten","Check the .sy file content and restore the {{...}} script section of the embed block","Restore the document from data history/snapshot if the embed node is corrupted"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const bt = GetBlockTree(id)\nif (!bt || bt.type !== 'query_embed') return null\n// no client-side way to inspect the script child node; treat parse failure as corrupt data","typeGuard":null,"tryCatchPattern":"try { return api.getQueryEmbedStatement(id) } catch (e) { if (String(e).includes('statement not found')) { reportCorruptEmbed(id); return null } throw e }","preventionTips":["Do not hand-edit .sy files; edit embed blocks through the editor","Restore corrupted documents from data history/snapshots","Keep SiYuan versions aligned across sync clients to avoid older serialization formats"],"tags":["embed-block","corrupt-data","siyuan"],"backgroundTag":"internal-invariant-violation","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"}