siyuan-note/siyuan · error
box document ID [ ] is already in use
Error message
box document ID [%s] is already in use
What it means
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.
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
Defensive patterns
Strategy: try-catch
Validate before calling
if (box.Exist(boxDocPath(boxID))) {
// hidden doc already created; skip creation path
} Try / catch
err := EnsureBoxDoc(boxID)
if err != nil && strings.Contains(err.Error(), "is already in use") {
// treat as already-initialized: proceed with existing box doc
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/1948abdb2988057e.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/box_doc.go:151
box := Conf.GetBox(boxID)
if nil == box {
return "", ErrBoxNotFound
}
if !IsBoxDocEnabled() {
return
}
boxDocID = boxID
boxDocID, err = findBoxDoc(box)
if err != nil {
return "", err
}
created, changed := false, false
if "" == boxDocID {
boxDocID = boxID
if box.Exist(boxDocPath(boxDocID)) || nil != treenode.GetBlockTree(boxDocID) || "" != findUnindexedTreePathInAllBoxes(boxDocID) {
return "", fmt.Errorf("box document ID [%s] is already in use", boxDocID)
}
if err = createBoxDoc(box, boxDocID); err != nil {
return "", err
}
created = true
changed = true
} else {
indexBoxDocIfNeeded(boxID, boxDocID)
if err = reconcileBoxDoc(box, boxDocID); err != nil {
return "", err
}
}
storedBoxDocID, _ := readBoxDocID(boxID)
if storedBoxDocID != boxID {
if err = writeBoxDocID(boxID); err != nil {
return "", err
}View on GitHub (pinned to 9f775e8a12)