siyuan-note/siyuan · error

get block tree by id [%s] failed after create

Error message

get block tree by id [%s] failed after create

What it means

verifyShorthandDocPersisted double-checks that a newly created shorthand document actually exists in the block tree and on disk. When the block tree lookup returned nil — the created document's ID is not registered — it returns "get block tree by id [%s] failed after create". This guards against a create that reported success but did not persist the tree record.

Source

Thrown at kernel/model/shortcuts.go:317

	retID, err = createDocsByHPathSync(box.ID, hPath, dom, "", docID, false)
	if nil != err {
		return
	}

	bt := treenode.GetBlockTree(retID)
	if err = verifyShorthandDocPersisted(bt, retID); nil != err {
		return
	}
	box.setSortByConf(path.Dir(bt.Path), retID)

	FlushTxQueue()
	PushCreate(box, bt.Path, nil)
	return
}

func verifyShorthandDocPersisted(bt *treenode.BlockTree, expectedID string) (err error) {
	if nil == bt {
		return fmt.Errorf("get block tree by id [%s] failed after create", expectedID)
	}
	// 清除写入缓存,确保从文件系统重新读取并验证文档。
	cache.RemoveTreeDataInBox(expectedID, bt.BoxID)
	persisted, err := loadTreeByBlockTree(bt)
	if nil != err {
		return fmt.Errorf("load created shorthand document [%s] failed: %w", expectedID, err)
	}
	if nil == persisted || persisted.ID != expectedID {
		return fmt.Errorf("verify created shorthand document [%s] failed", expectedID)
	}
	return nil
}

var consumeShorthandsLock = sync.Mutex{}
var shorthandSaveBoxUnavailableNotified bool

func isShorthandSaveBoxAvailable(box *Box) bool {
	return nil != box && !box.Closed && !box.Encrypted && !IsUserGuide(box.ID)

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Retry the shorthand creation — the failure is usually transient index timing
  2. Check blocktree.db integrity and rebuild the index if records are missing (rebuild index in Settings)
  3. Verify the notebook's .sy files on disk to see whether the doc file was written; if yes, re-index; if no, inspect create logs for the underlying failure

Example fix

null
Defensive patterns

Strategy: retry

Type guard

// nil-check the block tree record before verification
if bt == nil { return fmt.Errorf("get block tree by id [%s] failed after create", expectedID) }

Try / catch

if err := verifyShorthandDocPersisted(bt, expectedID); err != nil {
    time.Sleep(500 * time.Millisecond)
    bt = treenode.GetBlockTree(expectedID) // re-fetch; index may have settled
    err = verifyShorthandDocPersisted(bt, expectedID)
}

Prevention

When it happens

Trigger: createShorthandDocByDOM created the doc, then verifyShorthandDocPersisted receives a nil *treenode.BlockTree — e.g. the write failed silently, the block tree index was not updated, or a concurrent flush removed the record.

Common situations: Disk/index contention right after creation; asynchronous indexing not yet committed when verification runs; corrupted blocktree.db failing to return the new record; tests hitting timing windows.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/178e062c06c5c1dc. Report an issue: GitHub.