{"record":{"id":"5924ba19dd761926","repo":"siyuan-note/siyuan","slug":"parse-attribute-view-context-filter-w","errorCode":null,"errorMessage":"parse attribute view context filter: %w","messagePattern":"parse attribute view context filter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":5465,"sourceCode":"func GetAttributeViewContextFilter(attrView *av.AttributeView,\n\tblockID string) (ret *av.AttributeViewContextFilter, err error) {\n\tif nil == attrView || \"\" == blockID {\n\t\treturn\n\t}\n\tnode, _, err := getNodeByBlockID(nil, blockID)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\t// 普通内容块的数据库属性面板也会以内容块 ID 渲染属性视图，此时不存在块级上下文筛选。\n\tif nil == node || ast.NodeAttributeView != node.Type {\n\t\treturn nil, nil\n\t}\n\tif node.AttributeViewID != attrView.ID {\n\t\treturn nil, fmt.Errorf(\"block [%s] is not an instance of attribute view [%s]\", blockID, attrView.ID)\n\t}\n\tret, err = av.ParseAttributeViewContextFilter(node.IALAttr(av.NodeAttrContextFilter))\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"parse attribute view context filter: %w\", err)\n\t}\n\treturn\n}\n\nfunc getAttributeViewInstanceNode(attrView *av.AttributeView,\n\tblockID string) (node *ast.Node, tree *parse.Tree, err error) {\n\tif nil == attrView || \"\" == blockID {\n\t\treturn nil, nil, av.ErrAttributeViewNotFound\n\t}\n\tnode, tree, err = getNodeByBlockID(nil, blockID)\n\tif nil != err {\n\t\treturn\n\t}\n\tif nil == node || nil == tree || ast.NodeAttributeView != node.Type || node.AttributeViewID != attrView.ID {\n\t\treturn nil, nil, fmt.Errorf(\"block [%s] is not an instance of attribute view [%s]\", blockID, attrView.ID)\n\t}\n\treturn\n}","sourceCodeStart":5447,"sourceCodeEnd":5483,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/attribute_view.go#L5447-L5483","documentation":"Wraps an error from av.ParseAttributeViewContextFilter when the attribute view block's stored context-filter IAL value fails to parse into a valid AttributeViewContextFilter. The underlying error is preserved with %w; the wrapper adds the phase where parsing failed.","triggerScenarios":"Reading the context filter of a database block whose custom IAL attribute (the context-filter key) contains malformed, truncated, or schema-invalid JSON — e.g. written by an older version or corrupted during sync/undo replay.","commonSituations":"Undo/redo replay restored an IAL written before a filter-schema change; manual IAL editing produced invalid JSON; a sync conflict merged partial filter data.","solutions":["Clear the block's context-filter IAL attribute and reconfigure the filter in the UI","Inspect the IAL value and fix it to match the current AttributeViewContextFilter JSON schema","Update to the latest SiYuan version so the current filter schema is used for parsing"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const raw = node?.ial?.[\"custom-context-filter\"];\nif (raw) JSON.parse(raw); // throws early if malformed","typeGuard":null,"tryCatchPattern":"try { const f = await getAvContextFilter(blockID, avID); } catch (e) { if (String(e).includes(\"context filter\")) await clearAndReconfigureFilter(blockID); else throw e; }","preventionTips":["Do not hand-edit context-filter IAL values","Upgrade to the latest version before reading filters written by newer builds","Reconfigure filters after undo/redo anomalies"],"tags":["attribute-view","context-filter","json-parse"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}