siyuan-note/siyuan · error
parse encrypted notebook history conf
Error message
parse encrypted notebook history conf [%s] failed: %w
What it means
The .siyuan/conf.json of a history box is JSON-decoded into conf.BoxConf to read its Encrypted flag. This error is thrown when the file was read successfully but its bytes are not valid JSON or do not decode into conf.BoxConf — meaning the history box's configuration is corrupt, so its encrypted status is unknown and recovery classification stops for that box.
Solutions
- Restore the box's .siyuan/conf.json from a backup or sync snapshot taken before the corruption
- Validate/repair the JSON manually only after copying the original aside (keep recovery material intact)
- If the conf is from an old format, upgrade/migrate it with current tooling rather than deleting the box
- Never delete the history box on this error; classification failure must not remove recovery material
Example fix
// before: deleting a box whose conf cannot be parsed
if _, err := isEncryptedHistoryBoxDir(dir); err != nil {
os.RemoveAll(dir)
}
// after: quarantine instead of delete
if _, err := isEncryptedHistoryBoxDir(dir); err != nil {
os.Rename(dir, dir+".quarantine")
log.Printf("quarantined unparseable history box: %v", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
data, err := os.ReadFile(filepath.Join(boxDir, ".siyuan", "conf.json"))
if err == nil {
var probe conf.BoxConf
if jsonErr := json.Unmarshal(data, &probe); jsonErr != nil {
// corrupt conf — restore from backup before scanning
}
} Type guard
func isParsableBoxConf(data []byte) bool {
var c conf.BoxConf
return len(data) > 0 && json.Unmarshal(data, &c) == nil
} Try / catch
enc, err := isEncryptedHistoryBoxDir(boxDir)
if err != nil {
if strings.Contains(err.Error(), "parse encrypted notebook history conf") {
// restore conf.json from snapshot; keep the box regardless
}
return err
} Prevention
- Never hand-edit conf.json inside history boxes
- Shut the kernel down cleanly so conf writes complete
- Restore only whole boxes from backups, not partial files
- Quarantine boxes with unparseable conf instead of deleting them
When it happens
Trigger: filelock.ReadFile succeeds on <boxDir>/.siyuan/conf.json but gulu.JSON.UnmarshalJSON fails during a scan from encryptedNotebookHistoryBoxDirs, hasEncryptedNotebookDeleteHistory, or IsEncryptedHistoryPath — due to truncation, hand-editing, or an incompatible legacy conf format.
Common situations: A crash during a historic conf.json write left truncated JSON; the box came from a very old SiYuan version whose conf shape differs; the file was manually edited; a backup restored a partially written conf.json.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- unmarshal master password migration failed
- block ID must be text
- block operation result must be text, block IDs or null
- database back relation value is invalid
- database history contains an invalid field
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/72d4b1545cb20b33.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:954
if _, err := os.Stat(backupPath); err == nil {
return true, nil
} else if !os.IsNotExist(err) {
return false, fmt.Errorf("stat encrypted notebook history backup [%s] failed: %w", boxDir, err)
}
confPath := filepath.Join(siyuanDir, "conf.json")
if _, err := os.Stat(confPath); err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, fmt.Errorf("stat encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
data, err := filelock.ReadFile(confPath)
if err != nil {
return false, fmt.Errorf("read encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
var boxConf conf.BoxConf
if err = gulu.JSON.UnmarshalJSON(data, &boxConf); err != nil {
return false, fmt.Errorf("parse encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
return boxConf.Encrypted, nil
}
// cachedDEKs 缓存已解锁加密笔记本的 DEK,按 boxID 索引。
// KEK 不全局缓存("严格每笔记本单独解锁"语义):UnlockBox 临时派生 KEK 解出 DEK 后即丢弃 KEK,
// 仅保留 per-box DEK 供后续读写加解密。
var (
cachedDEKs = map[string][]byte{}
cachedDEKsLock sync.RWMutex
)
// boxLastAccess 记录每个加密笔记本最近一次真实用户交互或显式保活时间(unix 纳秒),供自动锁定 cron 使用。
// key: boxID, value: *atomic.Int64。UnlockBox 成功时初始化,Unmount 时清理。
var boxLastAccess sync.Map
// EnableEncryptedNotebookWithSync 在启用前先完成同步;同步恢复了既有配置时只校验原主密码。
func EnableEncryptedNotebookWithSync(password string) error {View on GitHub (pinned to 9f775e8a12)