siyuan-note/siyuan · error

get block tree by id

Error message

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

What it means

After creating a shorthand document the code verifies persistence. verifyShorthandDocPersisted is given the block tree record of the newly created document; if that record is nil (the block tree never registered the new document ID), it returns "get block tree by id [%s] failed after create" — the create apparently succeeded but left no index entry.

Solutions

  1. Retry the shorthand document creation; the second pass usually rebuilds the index entry
  2. Rebuild the block tree index (reindex the notebook) if entries are persistently missing
  3. Check for errors from the create path (createDocsByHPathSync) that may have been swallowed

Example fix

// before
bt := treenode.GetBlockTree(retID)
err = verifyShorthandDocPersisted(bt, retID)
// after
bt := treenode.GetBlockTree(retID)
if bt == nil {
    treenode.IndexTree(boxID) // force reindex, then retry
    bt = treenode.GetBlockTree(retID)
}
err = verifyShorthandDocPersisted(bt, retID)
Defensive patterns

Strategy: retry

Validate before calling

const bt = await api.getBlockTree(retID)
if (!bt) { await api.reindex(boxID); }

Type guard

function hasBlockTree(bt) { return bt != null && !!bt.id && !!bt.path }

Try / catch

try { await createShorthand(boxID, hPath, dom) } catch (e) { if (String(e).includes('failed after create')) { await sleep(1000); return createShorthand(boxID, hPath, dom); } throw e }

Prevention

When it happens

Trigger: createShorthandDocByDOM completes but treenode.GetBlockTree(returnedID) returns nil — e.g. the block tree index was not flushed, the create transaction was lost, or an ID mismatch between the created doc and the indexed record.

Common situations: Index/queue races under heavy load; crashes between writing the .sy file and updating blocktree.db; corrupt blocktree.db missing recent entries.

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@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/178e062c06c5c1dc. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/shortcuts.go:319

	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 9f775e8a12)