{"record":{"id":"ccb34b14fe6ca32c","repo":"siyuan-note/siyuan","slug":"errinvalidattributeviewid","errorCode":"ErrInvalidAttributeViewID","errorMessage":"invalid attribute view id","messagePattern":"invalid attribute view id","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/av.go","lineNumber":1340,"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":1322,"sourceCodeEnd":1358,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/av/av.go#L1322-L1358","documentation":"ErrInvalidAttributeViewID indicates the supplied avID string is not a syntactically valid SiYuan block/node ID (ast.IsNodeIDPattern check: 14-26 char base62-like ID). ParseAttributeView and ParseAttributeViewInBox reject such IDs before touching disk, and writeAttributeViewData also returns it when persisting data under an invalid AV id.","triggerScenarios":"Passing an empty string, a filename with extension (e.g. '20240101120000-abcdef.av'), a document path, or any malformed ID to ParseAttributeView / ParseAttributeViewInBox; calling writeAttributeViewData with an avID failing IsNodeIDPattern.","commonSituations":"Scripts splitting a .av filename and keeping the extension; treating a doc path or slug as an avID; off-by-one substring of an ID; copying an ID with surrounding whitespace or markdown characters.","solutions":["Validate the ID with ast.IsNodeIDPattern before calling the parse functions","Strip the .av extension via strings.TrimSuffix / filepath.Ext when deriving avID from a file path","Get the real avID from the block's attributes or the database UI rather than constructing one","Trim whitespace and ensure you use the 14-26 character node ID, not a filename or path"],"exampleFix":"// before\navID := filepath.Base(avPath) // \"20240101120000-abc.av\" -> ErrInvalidAttributeViewID\nattrView, _ := av.ParseAttributeView(avID)\n// after\navID := strings.TrimSuffix(filepath.Base(avPath), filepath.Ext(avPath))\nif !ast.IsNodeIDPattern(avID) {\n    return nil, fmt.Errorf(\"not a valid av id: %q\", avID)\n}\nattrView, _ := av.ParseAttributeView(avID)","handlingStrategy":"validation","validationCode":"if !ast.IsNodeIDPattern(avID) {\n    return fmt.Errorf(\"invalid attribute view id: %q\", avID)\n}","typeGuard":"func isValidAVID(s string) bool { return ast.IsNodeIDPattern(s) }","tryCatchPattern":"attrView, err := av.ParseAttributeView(avID)\nif errors.Is(err, av.ErrInvalidAttributeViewID) {\n    return fmt.Errorf(\"bad avID %q: expected a node ID, got a filename or path?\", avID)\n}","preventionTips":["Trim .av extensions and whitespace before deriving an avID from a path","Validate IDs with ast.IsNodeIDPattern before any kernel call","Copy IDs from the UI/API in full; never truncate or retype them"],"tags":["go","attribute-view","id-validation","input-validation"],"backgroundTag":"invalid-identifier-format","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}