siyuan-note/siyuan · error

Conf.Sync.Stat

Error message

Conf.Sync.Stat

What it means

When syncDataLocked returns an error during the encryption-enable prerequisite sync, SyncDataBeforeEnableEncryptedNotebook returns Conf.Sync.Stat verbatim if it is non-empty. Conf.Sync.Stat holds the human-readable status string written by the sync engine (e.g. 'network error', 'auth failed', 'index corrupt'), so the caller sees the real cause rather than a generic message. If Stat is empty, the raw error is returned instead.

Source

Thrown at kernel/model/sync.go:240

// SyncDataBeforeEnableEncryptedNotebook 在启用加密笔记本前执行一次完整同步。
// 未启用数据同步时直接返回;已启用数据同步时,任何同步失败都会阻止继续创建新的密钥体系。
func SyncDataBeforeEnableEncryptedNotebook() error {
	if !Conf.Sync.Enabled {
		return nil
	}
	if !cloud.IsValidCloudDirName(Conf.Sync.CloudName) {
		return errors.New(Conf.Language(123))
	}
	if !checkSync(false, false, true) {
		return errors.New(Conf.Language(53))
	}

	// 不复用请求合并状态,确保调用返回前确实完成了一次由当前启用操作发起的完整同步。
	lockSync()
	defer unlockSync()
	if err := syncDataLocked(false, true); err != nil {
		if Conf.Sync.Stat != "" {
			return errors.New(Conf.Sync.Stat)
		}
		return err
	}
	return nil
}

func lockSync() {
	syncLock.Lock()
	isSyncing.Store(true)
}

func unlockSync() {
	isSyncing.Store(false)
	syncLock.Unlock()
}

type syncRequestState struct {
	requested atomic.Uint64

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Read Conf.Sync.Stat / the UI sync status banner for the specific cause and address it (re-login, fix endpoint, free disk).
  2. Retry the encryption-enable once the underlying sync succeeds (run Sync now manually and confirm it reports success).
  3. If Stat points to a cloud lock, wait for the other client to finish or force-release per dejavu docs.

Example fix

// runtime error, not a code bug
// before: enable encryption -> sync fails with Stat='network error'
// after: resolve network/provider issue, sync succeeds, then enable
Defensive patterns

Strategy: try-catch

Validate before calling

// Cannot fully pre-validate network outcomes, but can preflight:
if !syncRunnable() { return errors.New("sync not runnable") }

Try / catch

// Go caller (e.g. crypto.go enable flow)
if err := model.SyncDataBeforeEnableEncryptedNotebook(); err != nil {
    logging.LogErrorf("prerequisite sync failed: %s", err)
    return err // surface Stat to the user, do not proceed to key creation
}

Prevention

When it happens

Trigger: The actual sync round fails after lockSync(): network/timeout talking to S3/WebDAV/cloud, authentication rejected, cloud lock contention (dejavu ErrLockCloudFailed), index fatal error, or system time incorrect. Any of these sets Conf.Sync.Stat and surfaces here.

Common situations: Cloud token expired. S3 endpoint unreachable / wrong region. WebDAV credentials changed. Two clients syncing concurrently and the cloud is locked by the other. Disk full or index corruption mid-sync.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/8eadcb0f47facc88. Report an issue: GitHub.