{"record":{"id":"530f5dff252d4cdc","repo":"siyuan-note/siyuan","slug":"encrypted-notebook-cannot-be-saved-as-a-normal-not","errorCode":null,"errorMessage":"encrypted notebook cannot be saved as a normal notebook","messagePattern":"encrypted notebook cannot be saved as a normal notebook","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/box_conf_crypto.go","lineNumber":99,"sourceCode":"\tif err := decryptBoxMetadata(boxID, boxConf, dek); err != nil {\n\t\tsetEncryptedBoxState(boxID, EncryptedBoxStateError)\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc prepareBoxConfForSave(boxID string, boxConf *conf.BoxConf) (*conf.BoxConf, error) {\n\tif boxConf == nil {\n\t\treturn nil, errors.New(\"notebook configuration is missing\")\n\t}\n\tpersisted := *boxConf\n\tpersisted.BoxCrypt = DeepCopyBoxEncryption(boxConf.BoxCrypt)\n\tif persisted.Encrypted {\n\t\tforgetRuntimeNormalBox(boxID)\n\t}\n\tif !persisted.Encrypted {\n\t\tif IsEncryptedBox(boxID) {\n\t\t\treturn nil, errors.New(\"encrypted notebook cannot be saved as a normal notebook\")\n\t\t}\n\t\treturn &persisted, nil\n\t}\n\tif persisted.BoxCrypt == nil {\n\t\tclearBoxMetadata(&persisted)\n\t\treturn &persisted, nil\n\t}\n\tif GetEncryptedBoxState(boxID) == EncryptedBoxStateError {\n\t\treturn nil, errors.New(\"encrypted notebook is in an error state\")\n\t}\n\n\tif dek, ok := cachedDEKCopy(boxID); ok {\n\t\tdefer zeroAndClear(dek)\n\t\tif err := reuseBoxMetadataIfUnchanged(boxID, &persisted, dek); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t} else if len(persisted.BoxCrypt.Metadata) == 0 {\n\t\texisting, err := readRawBoxConf(boxID)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/box_conf_crypto.go#L81-L117","documentation":"This error prevents silently converting an encrypted notebook back to a normal (unencrypted) one. When the incoming conf has Encrypted=false but the notebook on disk is still registered as encrypted (IsEncryptedBox), saving would drop encryption state, so the save is rejected. Encryption removal requires the explicit unencrypt flow, not a plain conf save.","triggerScenarios":"SaveConf called with a BoxConf whose Encrypted flag is false while IsEncryptedBox(boxID) returns true — e.g. a caller builds a fresh conf struct without preserving the Encrypted field, or UI code toggles encryption off directly through conf save.","commonSituations":"Plugin/API clients constructing BoxConf from scratch and defaulting Encrypted=false; syncing or importing conf fragments from a non-encrypted workspace; a bug that loses the Encrypted flag across a conf copy.","solutions":["Preserve the existing Encrypted=true field when building the BoxConf to save (copy it from the current box conf)","If decryption is truly intended, use the dedicated unencrypt/remove-encryption flow instead of SaveConf","Check IsEncryptedBox(boxID) before saving and merge the incoming conf with the persisted encryption state"],"exampleFix":"// before\nincoming := &conf.BoxConf{Icon: icon, Sort: sort} // Encrypted lost\nconf.SaveConf(boxID, incoming)\n// after\nexisting := Conf.GetBox(boxID)\nincoming.Encrypted = existing.Encrypted\nconf.SaveConf(boxID, incoming)","handlingStrategy":"validation","validationCode":"if !incoming.Encrypted && IsEncryptedBox(boxID) {\n    // do not save; route to the explicit unencrypt flow\n}","typeGuard":null,"tryCatchPattern":"if _, err := prepareBoxConfForSave(boxID, boxConf); err != nil && strings.Contains(err.Error(), \"cannot be saved as a normal notebook\") {\n    // preserve Encrypted=true and merge instead of overwriting\n}","preventionTips":["Copy the existing conf (including Encrypted) and mutate fields, never build BoxConf from scratch","Use the dedicated encryption-removal UI/flow to disable encryption","Check IsEncryptedBox before saving unencrypted confs"],"tags":["encryption","notebook","config","state-conflict"],"backgroundTag":"conflicting-config-options","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"}