{"record":{"id":"e7d59de193c01857","repo":"siyuan-note/siyuan","slug":"encrypted-notebook-is-in-an-error-state","errorCode":null,"errorMessage":"encrypted notebook is in an error state","messagePattern":"encrypted notebook is in an error state","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/box_conf_crypto.go","lineNumber":108,"sourceCode":"\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)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif existing == nil || existing.BoxCrypt == nil || len(existing.BoxCrypt.Metadata) == 0 {\n\t\t\treturn nil, errors.New(\"encrypted notebook metadata is missing\")\n\t\t}\n\t\tpersisted.BoxCrypt.Metadata = append([]byte(nil), existing.BoxCrypt.Metadata...)\n\t}\n\tif err := validateBoxEncryption(persisted.BoxCrypt); err != nil {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/box_conf_crypto.go#L90-L126","documentation":"The encrypted notebook's runtime state is marked EncryptedBoxStateError — an earlier decrypt/unlock step already failed — so prepareBoxConfForSave refuses to persist a new conf to avoid writing data derived from a broken encryption state. The save is aborted until the notebook's encryption state is fixed.","triggerScenarios":"SaveConf on a notebook for which GetEncryptedBoxState(boxID)==EncryptedBoxStateError, typically set by revealBoxMetadataIfUnlocked or unlockBoxHeld after a decryption/AAD verification failure earlier in the session.","commonSituations":"User entered a wrong passphrase earlier leaving the box in error state; metadata ciphertext corrupted; key material mismatch after restoring data from a different workspace without its keys.","solutions":["Re-unlock the notebook with the correct passphrase to clear the error state and repopulate the DEK cache","Restore the notebook's .siyuan config/metadata from a known-good backup, then retry","Restart the kernel and retry in case the error state came from a transient decryption failure","If the notebook's encryption state is unrecoverable, use the documented recovery/migration path rather than forcing a save"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if GetEncryptedBoxState(boxID) == EncryptedBoxStateError {\n    // require unlock/recovery before any save\n}","typeGuard":null,"tryCatchPattern":"_, err := prepareBoxConfForSave(boxID, boxConf)\nif err != nil && GetEncryptedBoxState(boxID) == EncryptedBoxStateError {\n    // surface recovery UI: re-enter passphrase or restore backup\n}","preventionTips":["Fix decryption failures promptly instead of saving through an error state","Re-unlock notebooks after key-material changes","Monitor box encryption state before batch conf writes"],"tags":["encryption","notebook","error-state","save-blocked"],"backgroundTag":"invalid-state-transition","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"}