{"record":{"id":"20b95e6159167ae1","repo":"siyuan-note/siyuan","slug":"notebook-configuration-is-missing","errorCode":null,"errorMessage":"notebook configuration is missing","messagePattern":"notebook configuration is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/box_conf_crypto.go","lineNumber":90,"sourceCode":"}\n\nfunc revealBoxMetadataIfUnlocked(boxID string, boxConf *conf.BoxConf) error {\n\tclearBoxMetadata(boxConf)\n\tdek, ok := cachedDEKCopy(boxID)\n\tif !ok {\n\t\treturn nil\n\t}\n\tdefer zeroAndClear(dek)\n\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\")","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/box_conf_crypto.go#L72-L108","documentation":"prepareBoxConfForSave rejects a save when the caller passes a nil notebook configuration pointer. SiYuan cannot build a persisted copy of a conf that does not exist, so it fails fast before touching the runtime normal-box registry or disk. This is a defensive argument check at the entry of the save path invoked by SaveConf.","triggerScenarios":"SaveConf (or any caller of prepareBoxConfForSave) passes boxID with a nil *conf.BoxConf, e.g. a nil entry in a conf map or a failed lookup being saved unconditionally.","commonSituations":"Programmatic API/plugin code calling the notebook-save endpoint with a missing or null conf object; a race where the notebook was closed/removed between lookup and save; code constructing BoxConf lazily and forgetting to allocate it.","solutions":["Ensure the BoxConf exists (Conf.GetBox(boxID) or equivalent) before calling SaveConf; create it if missing","Check for nil before saving and skip or return a friendly message instead of invoking the save path","Trace where the nil conf came from — typically a lookup failure for boxID that was ignored upstream"],"exampleFix":"// before\nconf.SaveConf(boxID, nil)\n// after\nif box := Conf.GetBox(boxID); box != nil {\n    conf.SaveConf(boxID, box.Conf)\n}","handlingStrategy":"validation","validationCode":"if boxConf == nil {\n    return fmt.Errorf(\"notebook %s has no configuration to save\", boxID)\n}","typeGuard":"func boxConfReady(bc *conf.BoxConf) bool { return bc != nil }","tryCatchPattern":"persisted, err := prepareBoxConfForSave(boxID, boxConf)\nif err != nil {\n    // nil conf: load or create the BoxConf and retry once\n}","preventionTips":["Always fetch the conf via the box registry instead of caching raw pointers","Check nil before invoking save paths","Handle notebook-removed races between lookup and save"],"tags":["nil-argument","notebook","config","save"],"backgroundTag":"null-argument","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"}