{"record":{"id":"f49f129732221a4b","repo":"siyuan-note/siyuan","slug":"database-history-contains-an-invalid-value","errorCode":null,"errorMessage":"database history contains an invalid value","messagePattern":"database history contains an invalid value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_block_history.go","lineNumber":51,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t} else if util.IsCiphertext(data) {\n\t\treturn nil, errors.New(\"encrypted database history has no notebook context\")\n\t}\n\tview, err := av.ParseAttributeViewData(avID, data)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif view.ID != avID {\n\t\treturn nil, errors.New(\"database history ID does not match its filename\")\n\t}\n\tfor _, kv := range view.KeyValues {\n\t\tif kv == nil || kv.Key == nil {\n\t\t\treturn nil, errors.New(\"database history contains an invalid field\")\n\t\t}\n\t\tfor _, value := range kv.Values {\n\t\t\tif value == nil {\n\t\t\t\treturn nil, errors.New(\"database history contains an invalid value\")\n\t\t\t}\n\t\t}\n\t}\n\tif view.GetBlockKeyValues() == nil {\n\t\treturn nil, errors.New(\"database history has no primary field\")\n\t}\n\tfor _, layout := range view.Views {\n\t\tif layout == nil {\n\t\t\treturn nil, errors.New(\"database history contains an invalid view\")\n\t\t}\n\t\tfor _, group := range layout.Groups {\n\t\t\tif group == nil {\n\t\t\t\treturn nil, errors.New(\"database history contains an invalid group\")\n\t\t\t}\n\t\t}\n\t}\n\treturn view, nil\n}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_block_history.go#L33-L69","documentation":"A parsed database history snapshot contains a nil Value inside one of its fields. Values must all be non-nil for the snapshot to be restorable; a nil value means the serialized history is incomplete or corrupt, so the engine rejects it before any restore attempt.","triggerScenarios":"readBoundAttributeViewHistory walking kv.Values where any value pointer is nil — from truncated history writes, interrupted snapshots, or externally modified history data.","commonSituations":"Interrupted backup/sync while the snapshot was written; corrupted storage; mixing history files from different SiYuan versions with divergent serialization.","solutions":["Pick a different, intact history snapshot to restore","Restore the corrupt history file from a backup copy","Generate a new snapshot by editing the database again, then restore from it","Check the storage/sync layer for reliability problems if snapshots keep arriving corrupt"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function hasValidValues(view) {\n  return view.keyValues.every(kv => kv.values.every(v => v));\n}","typeGuard":"const allValuesPresent = (view) =>\n  view.keyValues.every(kv => kv.values && kv.values.every(v => v != null));","tryCatchPattern":null,"preventionTips":["Ensure sync/backup completes before restoring history snapshots","Avoid mixing history files across SiYuan versions","Regenerate snapshots rather than repairing corrupt ones by hand","Monitor storage health where data/history lives"],"tags":["database","history","null-value","corruption"],"backgroundTag":"schema-validation-failed","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"}