siyuan-note/siyuan · error

unsupported attribute view key type

Error message

unsupported attribute view key type [%s]

What it means

newAttributeViewKey only accepts a fixed whitelist of key types (text, number, date, select, mSelect, url, email, phone, mAsset, template, created, updated, checkbox, relation, rollup, lineNumber). Any other string falls to the default branch and is rejected with the type echoed in the message.

Solutions

  1. Use one of the exact supported type strings (lowercase, e.g. "text", "mSelect", "mAsset")
  2. Compare against av.KeyType constants in the petal/plugin typings
  3. Update plugin code to current type names if it predates a rename

Example fix

// before
addAttrViewKey(avID, keyID, name, "Text", "", "")
// after
addAttrViewKey(avID, keyID, name, "text", "", "")
Defensive patterns

Strategy: type-guard

Validate before calling

const ADDABLE_TYPES = ["text","number","date","select","mSelect","url","email","phone","mAsset","template","created","updated","checkbox","relation","rollup","lineNumber"];
if (!ADDABLE_TYPES.includes(keyType)) throw new Error(`unsupported key type: ${keyType}`);

Type guard

type AddableKeyType = typeof ADDABLE_TYPES[number];
const isAddable = (t: string): t is AddableKeyType => ADDABLE_TYPES.includes(t);

Try / catch

try { await addAttrViewKey(...); } catch (e) { const m = String(e).match(/unsupported attribute view key type \[(.+)\]/); if (m) { console.error(`fix type "${m[1]}"`); } else throw e; }

Prevention

When it happens

Trigger: Calling add-attribute-view-key with a misspelled or nonexistent type string (e.g. "Text", "mulit-select", "assets").

Common situations: Case-sensitivity mistakes; outdated plugin using a removed/renamed type name; hand-written API scripts guessing type names.

Understand the failure class

Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/ba42644eb99ffd80. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/attribute_view.go:7478

	if nil != err {
		return err
	}
	addAttributeViewKey(attrView, currentView, key, previousKeyID)

	err = av.SaveAttributeView(attrView)
	return
}

func newAttributeViewKey(keyID, keyName, keyType, keyIcon string, dateFormat av.DateDisplayFormat) (ret *av.Key, err error) {
	keyTyp := av.KeyType(keyType)
	switch keyTyp {
	case av.KeyTypeBlock:
		return nil, errors.New("cannot add an attribute view block key")
	case av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail,
		av.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated, av.KeyTypeCheckbox,
		av.KeyTypeRelation, av.KeyTypeRollup, av.KeyTypeLineNumber:
	default:
		return nil, fmt.Errorf("unsupported attribute view key type [%s]", keyType)
	}

	ret = av.NewKey(keyID, keyName, filterAttrViewIconValue(keyIcon), keyTyp)
	if av.KeyTypeDate == keyTyp || av.KeyTypeCreated == keyTyp || av.KeyTypeUpdated == keyTyp {
		if !dateFormat.IsValid() {
			return nil, errors.New("invalid date display format")
		}
		ret.DateFormat = dateFormat
	}
	if av.KeyTypeRollup == keyTyp {
		ret.Rollup = &av.Rollup{Calc: &av.RollupCalc{Operator: av.CalcOperatorNone}}
	}
	return
}

func addAttributeViewKey(attrView *av.AttributeView, currentView *av.View, key *av.Key, previousKeyID string) {
	attrView.KeyValues = append(attrView.KeyValues, &av.KeyValues{Key: key})

View on GitHub (pinned to 9f775e8a12)