{"record":{"id":"1948abdb2988057e","repo":"siyuan-note/siyuan","slug":"box-document-id-s-is-already-in-use","errorCode":null,"errorMessage":"box document ID [%s] is already in use","messagePattern":"box document ID \\[(.+?)\\] is already in use","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/box_doc.go","lineNumber":151,"sourceCode":"\tbox := Conf.GetBox(boxID)\n\tif nil == box {\n\t\treturn \"\", ErrBoxNotFound\n\t}\n\n\tif !IsBoxDocEnabled() {\n\t\treturn\n\t}\n\tboxDocID = boxID\n\n\tboxDocID, err = findBoxDoc(box)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tcreated, changed := false, false\n\tif \"\" == boxDocID {\n\t\tboxDocID = boxID\n\t\tif box.Exist(boxDocPath(boxDocID)) || nil != treenode.GetBlockTree(boxDocID) || \"\" != findUnindexedTreePathInAllBoxes(boxDocID) {\n\t\t\treturn \"\", fmt.Errorf(\"box document ID [%s] is already in use\", boxDocID)\n\t\t}\n\t\tif err = createBoxDoc(box, boxDocID); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tcreated = true\n\t\tchanged = true\n\t} else {\n\t\tindexBoxDocIfNeeded(boxID, boxDocID)\n\t\tif err = reconcileBoxDoc(box, boxDocID); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\tstoredBoxDocID, _ := readBoxDocID(boxID)\n\tif storedBoxDocID != boxID {\n\t\tif err = writeBoxDocID(boxID); err != nil {\n\t\t\treturn \"\", err\n\t\t}","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/box_doc.go#L133-L169","documentation":"When ensureBoxDoc0 needs to create the box's hidden document it defaults the document ID to the box ID itself, but first checks that the ID is not already taken: it verifies no .sy file exists at the box doc path, no block-tree record exists, and no unindexed tree in any box occupies the ID. If any check matches, creation is refused with this error to avoid clobbering an existing document.","triggerScenarios":"EnsureBoxDoc/createBox called on a box whose box-ID-named document already exists on disk, is present in the block tree index, or exists as an unindexed .sy file in another notebook.","commonSituations":"Re-running box initialization after a previous run already created the hidden document; a stale or partially rebuilt blocktree index referencing the ID; copying a notebook that already contains the hidden doc.","solutions":["Check box.Exist(boxDocPath(boxID)) first and skip creation if the doc already exists","Rebuild the index if blocktree or unindexed trees falsely reference the ID","Choose a different, unused boxDocID when calling the underlying creation path"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (box.Exist(boxDocPath(boxID))) {\n  // hidden doc already created; skip creation path\n}","typeGuard":null,"tryCatchPattern":"err := EnsureBoxDoc(boxID)\nif err != nil && strings.Contains(err.Error(), \"is already in use\") {\n    // treat as already-initialized: proceed with existing box doc\n}","preventionTips":["Make box initialization idempotent: check existence before creating","Rebuild the index when blocktree state is suspected stale","Avoid copying notebooks that already contain the hidden doc into a workspace expecting fresh init"],"tags":["conflict","duplicate-id","notebook"],"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"}