siyuan-note/siyuan · error

verify created shorthand document

Error message

verify created shorthand document [%s] failed

What it means

Final verification step: after reloading the created shorthand document from disk, the tree must exist and its root ID must equal the expected document ID. If the tree is nil or the IDs differ, the created document did not persist correctly and "verify created shorthand document [%s] failed" is returned.

Solutions

  1. Re-run the creation and compare the returned ID with the persisted tree ID; investigate the mismatch source
  2. Avoid concurrent creates on the same hPath while shorthand import runs
  3. Check sync/history for an overwrite of the newly created document and restore it if needed

Example fix

// before
retID, _ := createDocsByHPathSync(...)  // assume retID == persisted root
// after
if persisted == nil || persisted.ID != expectedID {
    logging.LogErrorf("id mismatch: expected %s got %v", expectedID, persisted)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// compare the create call's returned ID with the ID you pass to verification
if (returnedID !== expectedID) throw new Error('create returned a different doc ID')

Type guard

function idMatches(persisted, expectedID) { return persisted != null && persisted.ID === expectedID }

Try / catch

try { await createShorthand(boxID, hPath, dom) } catch (e) { if (String(e).includes('verify created shorthand document')) { await api.exitSiYuan(); /* or */ flagDataIntegrityIssue(e); } throw e }

Prevention

When it happens

Trigger: loadTreeByBlockTree succeeds but returns a tree whose ID differs from expectedID — a document was created under a different ID than the one handed to verification, or the file on disk belongs to another/replaced document (e.g. overwritten by a concurrent create or sync).

Common situations: Concurrent document creation reusing paths so the loaded tree is a different document; ID mismatch between createDocsByHPathSync's return value and the persisted tree root; sync overwriting the new file with an older version.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/9f505d1aab955f8f. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/shortcuts.go:328

	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)
}

func selectShorthandSaveBox(configuredID string, boxes []*Box) *Box {
	if "" != configuredID {
		for _, box := range boxes {
			if nil != box && box.ID == configuredID && isShorthandSaveBoxAvailable(box) {
				return box
			}
		}

View on GitHub (pinned to 9f775e8a12)