siyuan-note/siyuan · error
cannot save incomplete notebook crypto configuration
Error message
cannot save incomplete notebook crypto configuration
What it means
saveNotebookCryptoBackup rejects the write when notebookCryptoConfigurationComplete(&nc) is false after preparing the copy and computing KEKMAC — i.e. the current NotebookCrypto configuration is missing required fields (salt, verifier, KDF params, etc.) and writing a backup of it would produce an unusable artifact. The mutex is released and nothing is persisted or copied back to Conf.
Solutions
- Inspect Conf.NotebookCrypto (conf.json) for missing required fields and re-run the enable/derive flow to populate them completely
- Restore conf.json from a known-good backup or re-enable encrypted notebooks from scratch (re-encrypting data)
- Ensure KEK derivation succeeded before the save call — a failed derivation can leave the config incomplete
- Check for recent version migrations that may have introduced partial configuration and apply the documented fix
Example fix
// before: saving with a half-initialized config
if err := saveNotebookCryptoBackup(kek); err != nil { /* incomplete config */ }
// after: complete the configuration first
nc.MasterSalt = newSalt
nc.KEKVerifier = makeVerifier(kek)
nc.KDFParams = params
applyNotebookCrypto(nc)
return saveNotebookCryptoBackup(kek) Defensive patterns
Strategy: validation
Validate before calling
Conf.m.RLock()
complete := notebookCryptoConfigurationComplete(Conf.NotebookCrypto)
Conf.m.RUnlock()
if !complete { return errors.New("refusing to save backup of incomplete config") } Type guard
null
Try / catch
if err := saveNotebookCryptoBackup(kek); err != nil {
if strings.Contains(err.Error(), "incomplete notebook crypto configuration") {
// inspect and repair Conf.NotebookCrypto before retrying
}
} Prevention
- Complete the full enable flow (salt, verifier, KDFParams, checksum) before any save call
- Validate conf.json integrity at startup and surface partial configurations early
- Avoid hand-editing conf.json; use the API/flows that populate all required fields
- Add a completeness assertion in tests around any code path that touches NotebookCrypto
When it happens
Trigger: Calling saveNotebookCryptoBackup while Conf.NotebookCrypto is only partially populated — e.g. encryption enablement failed midway, a migration left fields empty, or ChangeMasterPassword/deriveKEK ran against a config that lacks MasterSalt/KEKVerifier/KDFParams.
Common situations: Corrupted or partially written conf.json after a crash; manually edited configuration missing fields; a failed first-time enable of encrypted notebooks leaving a half-initialized NotebookCrypto; version migration bugs.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- 26
- Argon2id KeyLength must be 32
- Argon2id Memory too low (minimum 64 MB)
- cannot generate notebook crypto backup without KEK
- cannot write incomplete notebook crypto backup
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/00465dfc7c20c322.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:390
return nil
}
// saveNotebookCryptoBackup 把当前 NotebookCrypto(含 MasterSalt/KEKVerifier/KDFParams)备份到 DataDir。
// kek 必须非 nil:在 Checksum 定型后计算 KEKMAC 并落盘,保证恢复路径可通过 MAC 校验。
// 无 KEK 生成的备份 KEKMAC 必为空,会被 deriveKEK/恢复路径拒绝,等于制造无法解锁的状态(详见设计 §19)。
func saveNotebookCryptoBackup(kek []byte) error {
if kek == nil {
// 无 KEK 时不得生成当前格式备份:KEKMAC 缺失会被 deriveKEK/恢复路径拒绝,
// 生成即等于制造无法解锁的状态。
return errors.New("cannot generate notebook crypto backup without KEK")
}
Conf.m.Lock()
nc := *Conf.NotebookCrypto // 值拷贝
prepareBackupForWrite(&nc)
nc.KEKMAC = computeKEKMAC(&nc, kek)
if !notebookCryptoConfigurationComplete(&nc) {
Conf.m.Unlock()
return errors.New("cannot save incomplete notebook crypto configuration")
}
Conf.NotebookCrypto.Spec = nc.Spec
Conf.NotebookCrypto.BackupID = nc.BackupID
Conf.NotebookCrypto.CreatedAt = nc.CreatedAt
Conf.NotebookCrypto.Checksum = nc.Checksum
Conf.NotebookCrypto.KEKMAC = nc.KEKMAC // 保持 Conf 与备份文件的 KEKMAC 一致
Conf.m.Unlock()
backupPath := dataCryptoBackupPath()
if err := os.MkdirAll(filepath.Dir(backupPath), 0755); err != nil {
return fmt.Errorf("mkdir notebook crypto backup dir failed: %w", err)
}
data, err := json.Marshal(nc)
if err != nil {
return fmt.Errorf("marshal notebook crypto backup failed: %w", err)
}
if err := atomicWriteFile(backupPath, data); err != nil {
return fmt.Errorf("write notebook crypto backup failed: %w", err)
}View on GitHub (pinned to 9f775e8a12)