{"record":{"id":"e4fcf92b8a38d8a5","repo":"siyuan-note/siyuan","slug":"template-document-tree-plan-contains-an-unsupporte","errorCode":null,"errorMessage":"template document tree plan contains an unsupported parent undo operation","messagePattern":"template document tree plan contains an unsupported parent undo operation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":542,"sourceCode":"\treturn true, nil\n}\n\nfunc validateTemplateDocTreeParentOperations(transaction *Transaction) error {\n\tinverseActions := map[string]string{\n\t\t\"insert\":        \"delete\",\n\t\t\"delete\":        \"insert\",\n\t\t\"update\":        \"update\",\n\t\t\"foldHeading\":   \"unfoldHeading\",\n\t\t\"unfoldHeading\": \"foldHeading\",\n\t\t\"setAttrs\":      \"setAttrs\",\n\t}\n\tundoOperations := map[string]int{}\n\tfor _, operation := range transaction.UndoOperations {\n\t\tif nil == operation || \"\" == operation.ID {\n\t\t\treturn errors.New(\"template document tree plan contains an invalid parent undo operation\")\n\t\t}\n\t\tif _, supported := inverseActions[operation.Action]; !supported || \"\" != operation.RootID {\n\t\t\treturn errors.New(\"template document tree plan contains an unsupported parent undo operation\")\n\t\t}\n\t\tundoOperations[operation.Action+\"\\x00\"+operation.ID]++\n\t}\n\n\thasContentMutation := false\n\tfor _, operation := range transaction.DoOperations {\n\t\tif nil == operation || \"\" == operation.ID {\n\t\t\treturn errors.New(\"template document tree plan contains an invalid parent operation\")\n\t\t}\n\t\tinverseAction, supported := inverseActions[operation.Action]\n\t\tif !supported || \"\" != operation.RootID {\n\t\t\treturn errors.New(\"template document tree plan contains an unsupported parent operation\")\n\t\t}\n\t\tif \"insert\" == operation.Action || \"delete\" == operation.Action || \"update\" == operation.Action {\n\t\t\thasContentMutation = true\n\t\t}\n\t\tkey := inverseAction + \"\\x00\" + operation.ID\n\t\tif 1 > undoOperations[key] {","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L524-L560","documentation":"validateTemplateDocTreeParentOperations only permits undo operations whose Action has a known inverse (insert, delete, update, foldHeading, unfoldHeading, setAttrs) and whose RootID is empty. An undo action outside this whitelist, or one carrying a RootID (indicating a root-level/document-scoped operation the plan machinery cannot pair), is rejected as unsupported. This keeps the plan attachment restricted to block-level reversible operations.","triggerScenarios":"Attaching a plan to a transaction whose UndoOperations include an action not in inverseActions (e.g. appendBlock, moveBlock, custom plugin actions) or an undo operation with a non-empty RootID field.","commonSituations":"Plugin or API code attaching template doc-tree plans to transactions containing root-level or document-wide operations; version drift where a new operation action was introduced but not added to the inverse map; testing with synthetic operations that set RootID.","solutions":["Use only whitelisted actions (insert/delete/update/foldHeading/unfoldHeading/setAttrs) in parent operations","Clear the RootID field on undo operations, or move root-level work into a separate transaction","If a new action must be supported, add it to the inverseActions map in validateTemplateDocTreeParentOperations"],"exampleFix":"// before\nundo := &Operation{Action: \"appendBlock\", ID: id, RootID: rootID}\n// after\nundo := &Operation{Action: \"insert\", ID: id}","handlingStrategy":"validation","validationCode":"var inverseActions = map[string]bool{\"insert\": true, \"delete\": true, \"update\": true, \"foldHeading\": true, \"unfoldHeading\": true, \"setAttrs\": true}\nfor _, op := range tx.UndoOperations {\n    if !inverseActions[op.Action] || op.RootID != \"\" {\n        return errors.New(\"unsupported undo action: \" + op.Action)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only whitelisted block-level actions in parent transactions","Leave RootID empty on parent operations","Keep root-level work in separate transactions"],"tags":["go","transaction","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}