siyuan-note/siyuan · critical
notebook crypto backup is incomplete or corrupted
Error message
notebook crypto backup is incomplete or corrupted
What it means
After the spec check, loadNotebookCryptoBackup runs notebookCryptoConfigurationComplete on the parsed backup. If mandatory fields are missing, empty, or mutually inconsistent, the backup is deemed incomplete or corrupted and is rejected. This prevents restoring a backup that could never be authenticated, protecting recoverability of encrypted notebooks.
Solutions
- Restore the backup from a known-good copy (another snapshot, sync version history, OS backup)
- Regenerate the crypto configuration by re-running the enable-encryption setup with the master password if no valid backup exists
- Check the full JSON is present and valid (no truncation) with all required fields populated
- If corruption is environmental, check disk health and stop sync tools that might have truncated the file
Example fix
// before (truncated backup)
{"spec": 1, "masterSalt": "..."}
// after (complete backup restored from snapshot)
{"spec": 1, "masterSalt": "...", "wrappedDek": "...", "checksum": "...", "kekmac": "..."} Defensive patterns
Strategy: fallback
Validate before calling
var nc conf.NotebookCrypto
if err := json.Unmarshal(raw, &nc); err != nil || !notebookCryptoConfigurationComplete(&nc) {
return errors.New("backup is incomplete or corrupted; restore from a known-good copy")
} Try / catch
nc, err := loadNotebookCryptoBackup()
if err != nil {
if strings.Contains(err.Error(), "incomplete or corrupted") {
return tryAlternateBackupSnapshot() // sync history, OS backup
}
return err
} Prevention
- Keep at least one verified backup copy outside the data directory
- Never manually edit backup files; inspect copies, not originals
- Verify backup integrity after enabling encryption and after each master-password change
- Ensure writes complete cleanly: avoid killing the kernel during migration operations
When it happens
Trigger: Loading a backup whose JSON lacks required fields (MasterSalt, WrappedDEK, Checksum, KEKMAC, etc.) or has empty/malformed values: truncated file, partial write interrupted mid-save, manual editing, JSON that unmarshals with null fields, or corruption from a failing disk.
Common situations: Restore attempts after an interrupted master-password migration; a backup file truncated by disk-full during an old non-atomic write; user accidentally deleted fields while inspecting the JSON; data-directory corruption after a crash.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- cannot write incomplete notebook crypto backup
- unsupported notebook crypto backup spec
- all asset mappings failed
- assetPath is not an image referenced by the document
- assetPath is required for analyze
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/2e353499b43bb13f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:497
// loadNotebookCryptoBackup 从 DataDir 读取 NotebookCrypto 备份。文件不存在返回 (nil, nil)。
func loadNotebookCryptoBackup() (*conf.NotebookCrypto, error) {
data, err := filelock.ReadFile(dataCryptoBackupPath())
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
nc := &conf.NotebookCrypto{}
if err := json.Unmarshal(data, nc); err != nil {
return nil, err
}
if nc.Spec != conf.CurrentNotebookCryptoSpec {
return nil, fmt.Errorf("unsupported notebook crypto backup spec [%d]", nc.Spec)
}
if !notebookCryptoConfigurationComplete(nc) {
return nil, errors.New("notebook crypto backup is incomplete or corrupted")
}
return nc, nil
}
// removeNotebookCryptoBackup 删除备份文件(禁用加密功能时调用)。文件不存在视为成功。
func removeNotebookCryptoBackup() {
if err := os.Remove(dataCryptoBackupPath()); err != nil && !os.IsNotExist(err) {
logging.LogErrorf("remove notebook crypto backup failed: %s", err)
}
}
// masterPasswordMigration 记录改密迁移的完整状态,用于崩溃后恢复。
type masterPasswordMigration struct {
OldVerifier []byte `json:"oldVerifier"`
NewVerifier []byte `json:"newVerifier"`
NewVerifierNonce []byte `json:"newVerifierNonce"`
NewKDFParams json.RawMessage `json:"newKDFParams"`
NewHistoryKEKs [][]byte `json:"newHistoryKEKs,omitempty"`View on GitHub (pinned to 9f775e8a12)