{"record":{"id":"c720a3e19693819e","repo":"siyuan-note/siyuan","slug":"check-encrypted-notebook-history-failed-w","errorCode":null,"errorMessage":"check encrypted notebook history failed: %w","messagePattern":"check encrypted notebook history failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":1017,"sourceCode":"\t}\n\n\tnotebookCryptoMu.Lock()\n\tdefer notebookCryptoMu.Unlock()\n\n\tConf.m.RLock()\n\tcurrent := *Conf.NotebookCrypto\n\tConf.m.RUnlock()\n\tif current.Enabled && notebookCryptoConfigurationComplete(&current) {\n\t\treturn errors.New(Conf.Language(312))\n\t}\n\n\thasEncrypted, listErr := hasEncryptedNotebook()\n\tif listErr != nil {\n\t\treturn fmt.Errorf(\"list encrypted notebooks failed: %w\", listErr)\n\t}\n\thasHistory, historyErr := scanEncryptedNotebookHistory()\n\tif historyErr != nil {\n\t\treturn fmt.Errorf(\"check encrypted notebook history failed: %w\", historyErr)\n\t}\n\thasBackup := filelock.IsExist(dataCryptoBackupPath())\n\tif hasEncrypted || hasHistory || hasBackup {\n\t\t// 现存笔记本、已删除笔记本历史或全局备份均表示已有密钥域，必须恢复并认证，不能生成新 MasterSalt。\n\t\tkek, restoreErr := tryRestoreNotebookCryptoFromBackupLocked(password)\n\t\tif kek != nil {\n\t\t\tzeroAndClear(kek)\n\t\t}\n\t\tif restoreErr != nil {\n\t\t\tif strings.Contains(restoreErr.Error(), Conf.Language(311)) {\n\t\t\t\treturn errors.New(Conf.Language(311))\n\t\t\t}\n\t\t\treturn errors.New(Conf.Language(315))\n\t\t}\n\t\tlogging.LogInfof(\"encrypted notebook re-enabled with authenticated recovery key material\")\n\t\treturn nil\n\t}\n","sourceCodeStart":999,"sourceCodeEnd":1035,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L999-L1035","documentation":"During pre-enable checks, EnableEncryptedNotebook calls scanEncryptedNotebookHistory() to detect deleted-notebook history that indicates a prior key domain; if that scan errors the function returns fmt.Errorf(\"check encrypted notebook history failed: %w\", historyErr). Skipping the check could let a new MasterSalt overwrite a key domain still recoverable from history or the global backup.","triggerScenarios":"scanEncryptedNotebookHistory fails while EnableEncryptedNotebook (or EnableEncryptedNotebookWithSync) runs — usually history.db is unreadable/corrupt, the history directory has bad permissions, or an I/O error occurs during the scan.","commonSituations":"Corrupted or locked history.db in the workspace; partial restore or interrupted sync leaving history in a bad state; running without read permission on the history storage path; tests with a broken/missing history fixture.","solutions":["Inspect the wrapped cause (%w) for the underlying history-scan error and repair it (restore history.db from backup, fix permissions, free disk space)","Check the integrity of history.db (SQLite integrity check) and rebuild history indexes if corrupt","Retry after the environment is fixed; the scan is read-only","If a prior key domain is later detected, use the recovery-from-backup path instead of generating fresh key material"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := model.EnableEncryptedNotebook(password); err != nil {\n    if strings.Contains(err.Error(), \"check encrypted notebook history failed\") {\n        // inspect errors.Unwrap(err) for the history.db cause\n    }\n    return err\n}","preventionTips":["Keep history.db healthy: avoid killing the kernel mid-history-write and run integrity checks after crashes","Ensure read permissions on the workspace history storage path","Back up history.db and data/ crypto backup before enabling encryption","After an interrupted sync/restore, verify history integrity before re-attempting enable"],"tags":["filesystem","history-scan","wrapped-error"],"backgroundTag":"file-read-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}