{"record":{"id":"a6c5e2eb88283f3c","repo":"siyuan-note/siyuan","slug":"parse-attribute-view-s-in-box-s-failed-w","errorCode":null,"errorMessage":"parse attribute view [%s] in box [%s] failed: %w","messagePattern":"parse attribute view \\[(.+?)\\] in box \\[(.+?)\\] failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":656,"sourceCode":"\tcopySources := map[string]*av.AttributeView{}\n\tcopyBySourceID := map[string]*templateAttributeViewCopy{}\n\tboxID := templateAttributeViewBoxID(tree)\n\tast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {\n\t\tif !entering || ast.NodeAttributeView != n.Type {\n\t\t\treturn ast.WalkContinue\n\t\t}\n\n\t\tmode, modeErr := templateAttributeViewMode(n)\n\t\tif nil != modeErr {\n\t\t\terr = modeErr\n\t\t\treturn ast.WalkStop\n\t\t}\n\t\tif TemplateDatabaseModeReference == mode {\n\t\t\tsource := referenceSources[n.AttributeViewID]\n\t\t\tif nil == source {\n\t\t\t\tsource, modeErr = av.ParseAttributeViewInBox(n.AttributeViewID, boxID)\n\t\t\t\tif nil != modeErr {\n\t\t\t\t\terr = fmt.Errorf(\"parse attribute view [%s] in box [%s] failed: %w\", n.AttributeViewID, boxID, modeErr)\n\t\t\t\t\treturn ast.WalkStop\n\t\t\t\t}\n\t\t\t\tif nil == source || source.ID != n.AttributeViewID {\n\t\t\t\t\terr = fmt.Errorf(\"attribute view [%s] not found in box [%s]\", n.AttributeViewID, boxID)\n\t\t\t\t\treturn ast.WalkStop\n\t\t\t\t}\n\t\t\t\treferenceSources[n.AttributeViewID] = source\n\t\t\t}\n\t\t\tselectedView, validateErr := validateTemplateAttributeViewNode(n, source)\n\t\t\tif nil != validateErr {\n\t\t\t\terr = validateErr\n\t\t\t\treturn ast.WalkStop\n\t\t\t}\n\t\t\tplans[n] = &templateAttributeViewPlan{\n\t\t\t\tmode: mode, source: source, target: source, selectedView: selectedView,\n\t\t\t}\n\t\t\treturn ast.WalkContinue\n\t\t}","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L638-L674","documentation":"In reference mode, prepareTemplateAttributeViews parses the source attribute view from the template's box via av.ParseAttributeViewInBox. If that parse returns an error (unreadable or malformed database data for that box), the walk stops and the underlying error is wrapped with the attribute view ID and box ID. This distinguishes a parse failure from the separate 'not found in box' case that follows.","triggerScenarios":"Rendering a template whose database block uses `custom-av-mode=\"reference\"` while ParseAttributeViewInBox(attributeViewID, boxID) fails — the storage/av JSON for that ID in the box is malformed, unreadable, or fails parsing/validation inside the av package. In encrypted boxes the parse is scoped to the box ID; a wrong or inaccessible box triggers the same wrap.","commonSituations":"Databases corrupted by interrupted sync or disk issues, templates moved between boxes so the referenced database is absent in the current box's encrypted storage, or manual edits to storage/av/*.json breaking the schema.","solutions":["Check and repair the referenced attribute view by opening it in the UI; restore storage/av data from sync history or backup if it fails","Move the template back into the box containing the referenced database, or change the block to copy mode","Validate the attribute view JSON for syntax/schema damage before reloading","Recreate the referenced database and update the template's attribute-view ID"],"exampleFix":"<!-- before: reference mode with missing/corrupt source -->\n<div custom-av-mode=\"reference\" data-type=\"NodeAttributeView\" data-av-id=\"20240101120000-abc\"></div>\n<!-- after: copy mode falls back to embedded data -->\n<div custom-av-mode=\"copy\" data-type=\"NodeAttributeView\" data-av-id=\"20240101120000-abc\"></div>","handlingStrategy":"try-catch","validationCode":"try {\n  const av = await getAttrViewByID(avID);\n  if (!av) throw new Error(`attribute view ${avID} not readable in box`);\n} catch (e) { /* repair or switch to copy mode before rendering */ }","typeGuard":null,"tryCatchPattern":"try {\n  await insertTemplate(path);\n} catch (e) {\n  if (String(e).includes(\"parse attribute view\")) {\n    await restoreAttrViewFromHistory(avID); // or rewrite block to custom-av-mode=copy\n  }\n}","preventionTips":["Keep reference-mode databases inside the box the template targets","Enable sync history/backups so corrupted storage/av JSON is recoverable","Never hand-edit attribute view JSON; use the UI or API","Validate templates containing reference-mode databases in a test doc first"],"tags":["attribute-view","parse","box"],"backgroundTag":"file-read-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"}