{"record":{"id":"30a676f66f17b690","repo":"siyuan-note/siyuan","slug":"unsupported-notebook-crypto-backup-spec-d","errorCode":null,"errorMessage":"unsupported notebook crypto backup spec [%d]","messagePattern":"unsupported notebook crypto backup spec \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":494,"sourceCode":"\t}\n\treturn true\n}\n\n// loadNotebookCryptoBackup 从 DataDir 读取 NotebookCrypto 备份。文件不存在返回 (nil, nil)。\nfunc loadNotebookCryptoBackup() (*conf.NotebookCrypto, error) {\n\tdata, err := filelock.ReadFile(dataCryptoBackupPath())\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, err\n\t}\n\tnc := &conf.NotebookCrypto{}\n\tif err := json.Unmarshal(data, nc); err != nil {\n\t\treturn nil, err\n\t}\n\tif nc.Spec != conf.CurrentNotebookCryptoSpec {\n\t\treturn nil, fmt.Errorf(\"unsupported notebook crypto backup spec [%d]\", nc.Spec)\n\t}\n\tif !notebookCryptoConfigurationComplete(nc) {\n\t\treturn nil, errors.New(\"notebook crypto backup is incomplete or corrupted\")\n\t}\n\treturn nc, nil\n}\n\n// removeNotebookCryptoBackup 删除备份文件（禁用加密功能时调用）。文件不存在视为成功。\nfunc removeNotebookCryptoBackup() {\n\tif err := os.Remove(dataCryptoBackupPath()); err != nil && !os.IsNotExist(err) {\n\t\tlogging.LogErrorf(\"remove notebook crypto backup failed: %s\", err)\n\t}\n}\n\n// masterPasswordMigration 记录改密迁移的完整状态，用于崩溃后恢复。\ntype masterPasswordMigration struct {\n\tOldVerifier      []byte              `json:\"oldVerifier\"`\n\tNewVerifier      []byte              `json:\"newVerifier\"`","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L476-L512","documentation":"loadNotebookCryptoBackup reads the backup file and unmarshals it into conf.NotebookCrypto, then rejects any backup whose Spec field differs from conf.CurrentNotebookCryptoSpec. This ensures the kernel only restores backups written in the exact supported format version; older or newer (unknown) spec numbers are refused rather than guessed at.","triggerScenarios":"Loading a backup file whose JSON 'spec' value is not the current spec constant — e.g. a backup produced by an older SiYuan version before a format bump, a newer backup read by an older kernel, or a corrupted file where unmarshal left Spec at 0/default. Raised from restoreNotebookCryptoConfigFromBackup, deriveNotebookCryptoBackupCandidate, and deriveKEK paths.","commonSituations":"Downgrading the app after the crypto backup format was bumped; restoring a data directory copied from a newer installation; hand-edited or truncated backup JSON losing the spec field (defaults to 0); TestBackupRejectsIncompleteCurrentSpec-style corruption.","solutions":["Upgrade the kernel/app to a version whose conf.CurrentNotebookCryptoSpec matches the backup's spec value","If downgrading is required, first export/recover notebooks through the newer version before switching","Verify the backup file is intact and contains the correct spec field; restore from a known-good backup","Do not hand-edit the spec value — restore the original backup instead"],"exampleFix":"// before (hand-edited backup)\n{\"spec\": 0, ...}\n\n// after (restored from a compatible version's backup)\n{\"spec\": <CurrentNotebookCryptoSpec>, ...}","handlingStrategy":"fallback","validationCode":"var probe struct{ Spec int `json:\"spec\"` }\nif err := json.Unmarshal(raw, &probe); err != nil || probe.Spec != conf.CurrentNotebookCryptoSpec {\n    return errors.New(\"backup spec version is not supported by this kernel version\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := loadNotebookCryptoBackup(); err != nil {\n    if strings.Contains(err.Error(), \"unsupported notebook crypto backup spec\") {\n        // direct user to upgrade (or export via the matching version)\n    }\n    return err\n}","preventionTips":["Do not downgrade the app across crypto backup format bumps without exporting first","Keep backups produced by the running version; regenerate the backup after version upgrades","Never hand-edit the spec field in backup JSON"],"tags":["go","crypto","backup","versioning","format-compatibility"],"backgroundTag":"unsupported-enum-value","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"}