{"record":{"id":"bdf3f675330a1545","repo":"siyuan-note/siyuan","slug":"encrypted-notebook-metadata-is-missing","errorCode":null,"errorMessage":"encrypted notebook metadata is missing","messagePattern":"encrypted notebook metadata is missing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/box_conf_crypto.go","lineNumber":56,"sourceCode":"\t}\n\tmetadata := &encryptedBoxMetadata{\n\t\tIcon:     filterBoxIcon(boxConf.Icon),\n\t\tSort:     boxConf.Sort,\n\t\tSortMode: boxConf.SortMode,\n\t}\n\tplaintext, err := gulu.JSON.MarshalJSON(metadata)\n\tif err != nil {\n\t\treturn err\n\t}\n\tkey := util.DeriveSubKey(dek, \"siyuan/box-metadata\")\n\tdefer zeroAndClear(key)\n\tboxConf.BoxCrypt.Metadata, err = util.EncryptWithAAD(key, plaintext, boxMetadataAAD(boxID))\n\treturn err\n}\n\nfunc decryptBoxMetadata(boxID string, boxConf *conf.BoxConf, dek []byte) error {\n\tif boxConf == nil || boxConf.BoxCrypt == nil || len(boxConf.BoxCrypt.Metadata) == 0 {\n\t\treturn errors.New(\"encrypted notebook metadata is missing\")\n\t}\n\tkey := util.DeriveSubKey(dek, \"siyuan/box-metadata\")\n\tdefer zeroAndClear(key)\n\tplaintext, err := util.DecryptWithAAD(key, boxConf.BoxCrypt.Metadata, boxMetadataAAD(boxID))\n\tif err != nil {\n\t\treturn err\n\t}\n\tmetadata := &encryptedBoxMetadata{}\n\tif err = gulu.JSON.UnmarshalJSON(plaintext, metadata); err != nil {\n\t\treturn err\n\t}\n\tboxConf.Icon = filterBoxIcon(metadata.Icon)\n\tboxConf.Sort = metadata.Sort\n\tboxConf.SortMode = metadata.SortMode\n\treturn nil\n}\n\nfunc revealBoxMetadataIfUnlocked(boxID string, boxConf *conf.BoxConf) error {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/box_conf_crypto.go#L38-L74","documentation":"This error means the encrypted notebook's configuration has no encrypted metadata blob (BoxCrypt.Metadata) at all, so decryptBoxMetadata cannot attempt decryption. It is thrown as a guard before deriving the per-box subkey and calling DecryptWithAAD. It indicates the .siyuan box configuration for an encrypted notebook lost or never had its metadata ciphertext.","triggerScenarios":"Called from revealBoxMetadataIfUnlocked, reuseBoxMetadataIfUnchanged, or unlockBoxHeld when boxConf is nil, boxConf.BoxCrypt is nil, or len(boxConf.BoxCrypt.Metadata)==0 for a notebook treated as encrypted (e.g. unlock flow reads a box conf whose Metadata field is empty).","commonSituations":"Hand-edited or partially written .siyuan box config files; a downgraded or buggy older version that did not encrypt metadata; restoring a notebook from a backup that dropped the metadata field; corruption after an interrupted save.","solutions":["Check that the notebook's .siyuan box config file contains a non-empty BoxCrypt.Metadata field; if not, restore it from a backup or recreate the notebook configuration","Verify the notebook is actually encrypted (Encrypted=true) and its metadata was produced by encryptBoxMetadata; if the notebook should be unencrypted, clear the stale Encrypted flag","Re-open/unlock the notebook so the metadata is re-encrypted from current Icon/Sort/SortMode values via encryptBoxMetadata","If the config is unrecoverable, back up the data directory and let SiYuan rebuild the notebook configuration"],"exampleFix":"// before: attempting decrypt with empty metadata\nerr := decryptBoxMetadata(boxID, boxConf, dek) // errors: metadata missing\n// after: guard before calling\nif boxConf != nil && boxConf.BoxCrypt != nil && len(boxConf.BoxCrypt.Metadata) > 0 {\n    err := decryptBoxMetadata(boxID, boxConf, dek)\n}","handlingStrategy":"validation","validationCode":"if boxConf == nil || boxConf.BoxCrypt == nil || len(boxConf.BoxCrypt.Metadata) == 0 {\n    // restore from backup or re-enable encryption before decrypting\n}","typeGuard":"func hasEncryptedMetadata(bc *conf.BoxConf) bool {\n    return bc != nil && bc.BoxCrypt != nil && len(bc.BoxCrypt.Metadata) > 0\n}","tryCatchPattern":"if err := decryptBoxMetadata(boxID, boxConf, dek); err != nil {\n    // metadata missing or decryption failed: mark box in error state and prompt for recovery\n    setEncryptedBoxState(boxID, EncryptedBoxStateError)\n}","preventionTips":["Never hand-edit the .siyuan box config of encrypted notebooks","Back up the workspace before encryption-related operations","Verify BoxCrypt.Metadata survived any backup/restore or sync"],"tags":["encryption","notebook","config","missing-data"],"backgroundTag":"empty-required-field","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"}