{"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":"error_code","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/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template_doc_tree.go#L279-L315","documentation":"This error is thrown by validateLocations when rendering a template into a document tree plan: one of the generated node paths already exists in the notebook (box.Exist returns true). SiYuan refuses to overwrite an existing document, so the whole template application is aborted before any transaction runs. It is a pre-flight collision check on every flattened node path derived from the template.","triggerScenarios":"Calling the template rendering flow (renderTemplateSource -> validateLocations) where a computed child document path (nested by depth, '/' separated) collides with an existing document path in the target notebook. Happens when applying the same template twice to the same parent, or when the template hard-codes child paths that already exist.","commonSituations":"Re-applying a document-tree template without renaming; two users creating documents from the same template concurrently; template content containing fixed child names like 'Inbox/Notes' that already exist in the workspace; syncing another device's created docs before re-running the template.","solutions":["Rename or delete the existing document(s) whose path matches the template's generated path, then re-apply the template","Change the template so child paths are unique (e.g. include the template's rendered name/date placeholder)","Apply the template under a different parent document so the computed paths no longer collide","If the collision is unexpected, verify which node path is reported in the message and inspect the notebook via the document tree for stale duplicates"],"exampleFix":"// before: template child path hard-coded, collides on second apply\nchildPath := parentPath + \"/Notes\"\n// after: make the path unique per apply\ncleanName := strings.ReplaceAll(time.Now().Format(\"2006-01-02 15:04:05\"), \":\", \"-\")\nchildPath := parentPath + \"/Notes \" + cleanName","handlingStrategy":"validation","validationCode":"// Go: check all template-generated paths before applying\nfor _, p := range plannedPaths {\n    if box.Exist(p) {\n        return fmt.Errorf(\"path %s already exists in notebook\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":"// catch and surface which path collided so the user can rename or relocate\nif err := validateLocations(...); err != nil {\n    log.Printf(\"template apply blocked: %v\", err)\n    return userFacingRenameOrAbort()\n}","preventionTips":["Include a unique placeholder (date/time or rendered doc name) in template child paths","Check existing documents under the target parent before applying a template","Avoid applying the same fixed-path template twice without renaming","After sync, re-check for conflicts before re-running templates"],"tags":["template","document-tree","path-collision","siyuan-kernel"],"backgroundTag":"file-already-exists","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}