siyuan-note/siyuan · error

check encrypted notebook history failed: %w

Error message

check encrypted notebook history failed: %w

What it means

EnableEncryptedNotebook returns a wrapped error at line 995 when scanEncryptedNotebookHistory() fails. This scan inspects deleted-notebook history for encrypted notebooks to ensure a new key domain is not created over history that would become unrecoverable. If the history scan errors, the function aborts (fail-closed) rather than risk orphaning historical WrappedDEKs.

Source

Thrown at kernel/model/crypto.go:995

	}

	notebookCryptoMu.Lock()
	defer notebookCryptoMu.Unlock()

	Conf.m.RLock()
	current := *Conf.NotebookCrypto
	Conf.m.RUnlock()
	if current.Enabled && notebookCryptoConfigurationComplete(&current) {
		return errors.New(Conf.Language(312))
	}

	hasEncrypted, listErr := hasEncryptedNotebook()
	if listErr != nil {
		return fmt.Errorf("list encrypted notebooks failed: %w", listErr)
	}
	hasHistory, historyErr := scanEncryptedNotebookHistory()
	if historyErr != nil {
		return fmt.Errorf("check encrypted notebook history failed: %w", historyErr)
	}
	hasBackup := filelock.IsExist(dataCryptoBackupPath())
	if hasEncrypted || hasHistory || hasBackup {
		// 现存笔记本、已删除笔记本历史或全局备份均表示已有密钥域,必须恢复并认证,不能生成新 MasterSalt。
		kek, restoreErr := tryRestoreNotebookCryptoFromBackupLocked(password)
		if kek != nil {
			zeroAndClear(kek)
		}
		if restoreErr != nil {
			if strings.Contains(restoreErr.Error(), Conf.Language(311)) {
				return errors.New(Conf.Language(311))
			}
			return errors.New(Conf.Language(315))
		}
		logging.LogInfof("encrypted notebook re-enabled with authenticated recovery key material")
		return nil
	}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Inspect the wrapped underlying error to localize the failure (history.db vs directory traversal).
  2. Repair history storage (permissions, reindex history, free disk) and retry the enable.
  3. Treat the failure as fail-closed — do not force-enable while history state is uncertain.
Defensive patterns

Strategy: try-catch

Try / catch

// Unwrap the history-scan failure for targeted repair.
if err := model.EnableEncryptedNotebook(password); err != nil {
    if strings.Contains(err.Error(), "encrypted notebook history") {
        // inspect/repair history.db and the history directory, then retry
    }
}

Prevention

When it happens

Trigger: scanEncryptedNotebookHistory() returns a non-nil error while scanning deleted-notebook history records for encryption markers. Causes: history.db read failure, corrupted history index, or filesystem error traversing the history directory.

Common situations: history.db locked or corrupt; history directory permission error; large history triggering a timeout/OOM during scan; storage degradation affecting the history volume.

Related errors


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