{"record":{"id":"e87cfb4231582729","repo":"siyuan-note/siyuan","slug":"document-path-s-already-exists","errorCode":null,"errorMessage":"document path [%s] already exists","messagePattern":"document path \\[(.+?)\\] already exists","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":297,"sourceCode":"\tfor _, node := range nodes {\n\t\tret = append(ret, node)\n\t\tret = append(ret, flattenTemplateDocTreeNodes0(node.Children)...)\n\t}\n\treturn\n}\n\nfunc (collector *templateDocTreeCollector) validateLocations() error {\n\tbox := Conf.Box(collector.boxID)\n\tif nil == box {\n\t\treturn ErrBoxNotFound\n\t}\n\tallowCreateDeeper := nil != Conf.FileTree && Conf.FileTree.AllowCreateDeeper\n\tfor _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {\n\t\tif depth := strings.Count(node.path, \"/\"); 7 < depth && !allowCreateDeeper {\n\t\t\treturn errors.New(Conf.Language(118))\n\t\t}\n\t\tif box.Exist(node.path) {\n\t\t\treturn fmt.Errorf(\"document path [%s] already exists\", node.path)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (collector *templateDocTreeCollector) buildTree(node *TemplateDocTreeNode, renderedTree *parse.Tree) {\n\trenderedRootID := renderedTree.Root.ID\n\trenderedTree.Box = collector.boxID\n\trenderedTree.Path = node.path\n\trenderedTree.HPath = node.HPath\n\trenderedTree.ID = node.ID\n\trenderedTree.Root.ID = node.ID\n\trenderedTree.Root.Spec = treenode.CurrentSpec\n\ttemplateIALs := parse.IAL2Map(renderedTree.Root.KramdownIAL)\n\trenderedTree.Root.KramdownIAL = [][]string{\n\t\t{\"id\", node.ID},\n\t\t{\"title\", html.EscapeAttrVal(node.Title)},\n\t\t{\"updated\", util.TimeFromID(node.ID)},","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L279-L315","documentation":"validateLocations checks that no document to be created by the doc-tree template already exists in the notebook. If box.Exist(node.path) reports an existing document at the target path, creation is aborted with this error to avoid overwriting or merging into existing content.","triggerScenarios":"Inserting a doc-tree template whose computed paths (root path + node paths) collide with documents that already exist in the box — e.g. re-running the same template insertion twice, or two nodes resolving to the same path.","commonSituations":"Running the same doc-tree template a second time into the same parent; duplicate sibling names within the template causing identical paths; the target parent document already containing a child with the template's root name.","solutions":["Choose a different target parent or rename so the computed paths are free","Delete or rename the conflicting existing document before re-running the template","Ensure the template's node paths are unique among themselves"],"exampleFix":"// before: same template re-run into same parent, path /parent/MyTemplate exists\ncreateDocTree(box, \"/parent\", \"MyTemplate\", def) // error\n// after: unique root name per run\ncreateDocTree(box, \"/parent\", \"MyTemplate 2026-09-18\", def)","handlingStrategy":"validation","validationCode":"for _, n := range nodes { if box.Exist(n.path) { return fmt.Errorf(\"path %s exists\", n.path) } }","typeGuard":null,"tryCatchPattern":"err := validateLocations(collector, box)\nif err != nil && strings.Contains(err.Error(), \"already exists\") {\n  // pick a new root name/parent or rename the existing doc\n}","preventionTips":["Use unique, timestamped root names for repeated template runs","Check the target parent for name collisions before inserting","Ensure template sibling paths are unique within the definition"],"tags":["go","template","conflict","duplicate"],"backgroundTag":"file-already-exists","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"}