{"record":{"id":"ccb34b14fe6ca32c","repo":"siyuan-note/siyuan","slug":"errinvalidattributeviewid","errorCode":"ErrInvalidAttributeViewID","errorMessage":"invalid attribute view id","messagePattern":"invalid attribute view id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/av.go","lineNumber":1384,"sourceCode":"\n\tav := filepath.Join(util.DataDir, \"storage\", \"av\")\n\tret = filepath.Join(av, avID+\".json\")\n\tif !gulu.File.IsDir(av) {\n\t\tif err := os.MkdirAll(av, 0755); err != nil {\n\t\t\tlogging.LogErrorf(\"create attribute view dir failed: %s\", err)\n\t\t\treturn\n\t\t}\n\t}\n\treturn\n}\n\nfunc GetAttributeViewI18n(key string) string {\n\treturn util.AttrViewLangs[util.Lang][key].(string)\n}\n\nvar (\n\tErrAttributeViewNotFound  = errors.New(\"attribute view not found\")\n\tErrInvalidAttributeViewID = errors.New(\"invalid attribute view id\")\n\tErrInvalidBoxID           = errors.New(\"invalid box id\")\n\tErrViewNotFound           = errors.New(\"view not found\")\n\tErrKeyNotFound            = errors.New(\"key not found\")\n\tErrItemNotFound           = errors.New(\"item not found\")\n\tErrWrongLayoutType        = errors.New(\"wrong layout type\")\n\tErrInvalidColumnAlign     = errors.New(\"invalid column align\")\n\tErrSpecTooNew             = errors.New(\"attribute view spec is too new\")\n\tErrRichTextSpecMismatch   = errors.New(\"attribute view rich text requires storage spec 9\")\n\tErrFilterTooDeep          = errors.New(\"filter nesting depth exceeds the maximum allowed\")\n)\n\nconst (\n\tNodeAttrNameAvs        = \"custom-avs\"                  // 用于标记块所属的属性视图，逗号分隔 av id\n\tNodeAttrView           = \"custom-sy-av-view\"           // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443\n\tNodeAttrVisibleViewIDs = \"custom-sy-av-visible-views\"  // 用于标记数据库块显示的视图 ID，逗号分隔\n\tNodeAttrContextFilter  = \"custom-sy-av-context-filter\" // 用于保存数据库块独有的上下文筛选配置\n\tNodeAttrViewStaticText = \"custom-sy-av-s-text\"         // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049\n","sourceCodeStart":1366,"sourceCodeEnd":1402,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/av.go#L1366-L1402","documentation":"ErrInvalidAttributeViewID is returned when an ID string passed to attribute-view parsing functions does not match the required node-ID pattern (a valid SiYuan block ID). Parsing is refused before any file access, since a malformed ID can never map to a real attribute view.","triggerScenarios":"Calling parseAttributeView/parseAttributeViewInBox (and higher-level APIs that use them) with avID values like \"\", \"tmp\", UUIDs, or strings failing ast.IsNodeIDPattern (14-26 chars of the expected charset with a timestamp-date prefix); writing AV data via writeAttributeViewData with a bad ID; user-supplied IDs from URL params passed through unchecked.","commonSituations":"Extracting the wrong substring from a filename or URL; hard-coded placeholder IDs in scripts; concatenating IDs with suffixes/paths; frontend passing an empty avID for an unsaved block.","solutions":["Validate the ID locally with the same rule: /^\\d{14}-[0-9a-z]{7}$/ (timestamp-prefixed, lowercase alnum suffix) before calling the API","Take the avID from the block's attributes (e.g. custom-av keys or the .av filename base) rather than free-form input","Fix empty/placeholder IDs in the calling code path — log the received value to find where it originates"],"exampleFix":"// before\nawait fetchPost(\"/api/av/renderAttributeView\", {id: window.location.hash.slice(1)})\n// after\nconst id = window.location.hash.slice(1)\nif (!/^\\d{14}-[0-9a-z]{7}$/.test(id)) throw new Error(\"invalid attribute view id: \" + id)\nawait fetchPost(\"/api/av/renderAttributeView\", {id})","handlingStrategy":"validation","validationCode":"const AV_ID_RE = /^\\d{14}-[0-9a-z]{7}$/\nif (!AV_ID_RE.test(avID)) throw new Error(\"invalid attribute view id: \" + avID)","typeGuard":"const isAVID = (s) => typeof s === \"string\" && /^\\d{14}-[0-9a-z]{7}$/.test(s);","tryCatchPattern":"try {\n  return await fetchPost(\"/api/av/renderAttributeView\", {id: avID})\n} catch (e) {\n  if (e.message.includes(\"invalid attribute view id\")) console.error(\"bad avID:\", avID)\n  throw e\n}","preventionTips":["Validate IDs against the SiYuan node-ID pattern before any API call","Never slice/substring block IDs to derive avIDs; read them from block attributes or .av filenames","Reject empty strings and URL-encoded values early at input boundaries"],"tags":["attribute-view","validation","identifier"],"backgroundTag":"invalid-identifier-format","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"}