siyuan-note/siyuan · error
ErrInvalidAttributeViewID
ErrInvalidAttributeViewID
Error message
invalid attribute view id
What it means
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.
Source
Thrown at kernel/av/av.go:1340
av := filepath.Join(util.DataDir, "storage", "av")
ret = filepath.Join(av, avID+".json")
if !gulu.File.IsDir(av) {
if err := os.MkdirAll(av, 0755); err != nil {
logging.LogErrorf("create attribute view dir failed: %s", err)
return
}
}
return
}
func GetAttributeViewI18n(key string) string {
return util.AttrViewLangs[util.Lang][key].(string)
}
var (
ErrAttributeViewNotFound = errors.New("attribute view not found")
ErrInvalidAttributeViewID = errors.New("invalid attribute view id")
ErrInvalidBoxID = errors.New("invalid box id")
ErrViewNotFound = errors.New("view not found")
ErrKeyNotFound = errors.New("key not found")
ErrItemNotFound = errors.New("item not found")
ErrWrongLayoutType = errors.New("wrong layout type")
ErrInvalidColumnAlign = errors.New("invalid column align")
ErrSpecTooNew = errors.New("attribute view spec is too new")
ErrRichTextSpecMismatch = errors.New("attribute view rich text requires storage spec 9")
ErrFilterTooDeep = errors.New("filter nesting depth exceeds the maximum allowed")
)
const (
NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id
NodeAttrView = "custom-sy-av-view" // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443
NodeAttrVisibleViewIDs = "custom-sy-av-visible-views" // 用于标记数据库块显示的视图 ID,逗号分隔
NodeAttrContextFilter = "custom-sy-av-context-filter" // 用于保存数据库块独有的上下文筛选配置
NodeAttrViewStaticText = "custom-sy-av-s-text" // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049
View on GitHub (pinned to 8641553a1f)
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
Example fix
// before
avID := filepath.Base(avPath) // "20240101120000-abc.av" -> ErrInvalidAttributeViewID
attrView, _ := av.ParseAttributeView(avID)
// after
avID := strings.TrimSuffix(filepath.Base(avPath), filepath.Ext(avPath))
if !ast.IsNodeIDPattern(avID) {
return nil, fmt.Errorf("not a valid av id: %q", avID)
}
attrView, _ := av.ParseAttributeView(avID) Defensive patterns
Strategy: validation
Validate before calling
if !ast.IsNodeIDPattern(avID) {
return fmt.Errorf("invalid attribute view id: %q", avID)
} Type guard
func isValidAVID(s string) bool { return ast.IsNodeIDPattern(s) } Try / catch
attrView, err := av.ParseAttributeView(avID)
if errors.Is(err, av.ErrInvalidAttributeViewID) {
return fmt.Errorf("bad avID %q: expected a node ID, got a filename or path?", avID)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/ccb34b14fe6ca32c.
Report an issue: GitHub.