{"record":{"id":"df5870dd837c5f7a","repo":"siyuan-note/siyuan","slug":"created-doc-path-s-already-exists","errorCode":null,"errorMessage":"created doc path [%s] already exists","messagePattern":"created doc path \\[(.+?)\\] already exists","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/transaction.go","lineNumber":2813,"sourceCode":"\t\t\top.Data = nil\n\t\t}\n\t}\n\tfor _, op := range tx.UndoOperations {\n\t\tif _, ok := op.Data.(*parse.Tree); ok {\n\t\t\tif nil == op.Tree {\n\t\t\t\top.Tree = op.Data.(*parse.Tree)\n\t\t\t}\n\t\t\top.Data = nil\n\t\t}\n\t}\n\tfor _, tree := range orderedTrees {\n\t\tif _, restored := restoredIDs[tree.ID]; restored {\n\t\t\tbox := Conf.Box(tree.Box)\n\t\t\tif nil == box {\n\t\t\t\treturn ErrBoxNotFound\n\t\t\t}\n\t\t\tif box.Exist(tree.Path) {\n\t\t\t\treturn fmt.Errorf(\"created doc path [%s] already exists\", tree.Path)\n\t\t\t}\n\t\t\ttx.attemptedTemplateCreatedDocs[tree.ID] = tree\n\t\t}\n\t\twriteTransactionTree := tx.writeTransactionTree\n\t\tif nil == writeTransactionTree {\n\t\t\twriteTransactionTree = writeTreeUpsertQueue\n\t\t}\n\t\tif err = writeTransactionTree(tree); err != nil {\n\t\t\treturn\n\t\t}\n\n\t\tvar sources []any\n\t\tsources = append(sources, tx)\n\t\tutil.PushSaveDoc(tree.ID, \"tx\", sources)\n\n\t\tcheckUpsertInUserGuide(tree)\n\t}\n\tfor boxID, icon := range tx.boxIcons {","sourceCodeStart":2795,"sourceCodeEnd":2831,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/transaction.go#L2795-L2831","documentation":"During transaction commit compensation, each tree flagged as restored (present in restoredIDs) is re-written, but only if its target path is free. If the path the created doc would occupy already exists on disk, proceeding would overwrite an existing document, so the commit aborts with the offending path in the message.","triggerScenarios":"Replaying/retrying a transaction that already created the document in a prior (partially applied) attempt, so box.Exist(tree.Path) is true for a restored tree ID.","commonSituations":"A previous transaction attempt crashed after creating the doc but before completing; manual creation of a document with the same path; sync restored a doc at the same path before the retry.","solutions":["Remove or rename the existing document at the reported path, then retry","Delete the leftover doc from the failed prior attempt (same ID/content)","Change the new document's name so its path is unique","Inspect data/<box>/ to confirm the leftover file before deleting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if box.Exist(tree.Path) { /* rename target or clean up leftover doc before committing */ }","typeGuard":null,"tryCatchPattern":"if err := tx.Commit(); err != nil && strings.Contains(err.Error(), \"already exists\") { cleanupLeftoverDoc(path); retry() }","preventionTips":["Clean up leftover documents from failed transaction attempts before retrying","Avoid retrying a transaction that partially succeeded","Ensure doc names produce unique paths","Check the reported path on disk before re-issuing create operations"],"tags":["transaction","filesystem","conflict"],"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"}