siyuan-note/siyuan · error
ErrKeyNotFound
ErrKeyNotFound
Error message
key not found
What it means
ErrKeyNotFound is returned by AttributeView.GetKey and GetKeyValues when no key (column/field) with the requested keyID exists in the parsed attribute view. Update paths (e.g. updateAttributeViewValue) use it to abort operations that would otherwise write a value into a non-existent column.
Source
Thrown at kernel/av/av.go:1343
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
NodeAttrViewNames = "av-names" // 用于临时标记块所属的属性视图名称,空格分隔
)
View on GitHub (pinned to 8641553a1f)
Solutions
- Re-read the attribute view and resolve the key by name/type to get its current keyID before updating
- Check errors.Is(err, av.ErrKeyNotFound) and skip or recreate the column as appropriate
- Confirm the keyID belongs to the same avID you are operating on
- Recreate the deleted column if the values are still required
Example fix
// before
attrView.UpdateAttributeViewValue(nil, keyID, itemID, val) // ErrKeyNotFound
// after
if _, err := attrView.GetKey(keyID); errors.Is(err, av.ErrKeyNotFound) {
key := findKeyByName(attrView, "Status") // re-resolve current ID
keyID = key.ID
} Defensive patterns
Strategy: type-guard
Validate before calling
if _, err := attrView.GetKey(keyID); err != nil {
return fmt.Errorf("key %s missing in av %s", keyID, attrView.ID)
} Type guard
func keyExists(attrView *av.AttributeView, keyID string) bool {
_, err := attrView.GetKey(keyID)
return !errors.Is(err, av.ErrKeyNotFound)
} Try / catch
err := updateAttrViewValue(avID, keyID, itemID, value)
if errors.Is(err, av.ErrKeyNotFound) {
keyID = resolveKeyIDByName(avID, columnName) // re-resolve, then retry once
err = updateAttrViewValue(avID, keyID, itemID, value)
} Prevention
- Re-resolve key IDs by column name after any user-triggered schema change
- Scope key IDs to one avID — never reuse IDs across databases
- Wrap update calls with errors.Is checks against av.ErrKeyNotFound
When it happens
Trigger: Looking up or updating a field by keyID that is not in av.KeyValues — deleted column, wrong column ID, or keyID belonging to a different attribute view; TestUpdateAttributeViewValueRejectsMissingKey exercises exactly this.
Common situations: A plugin cached a key ID and the user later deleted that column; column IDs copied between two different databases; script typo or truncated key ID; sync conflict removed the column while an update was queued.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/acc1073f012413ff.
Report an issue: GitHub.