siyuan-note/siyuan · error

phone value is missing

Error message

phone value is missing

What it means

Thrown inside normalizeNewItemTemplateValue (kernel/av/new_item_template.go:397-398) when key.Type == KeyTypePhone but value.Phone is nil. The normalizer clones the Value and nulls out all sub-fields except Phone, so a nil *ValuePhone makes the template field unusable. The strict path wraps it as "new item template field [<keyID>] value is invalid: phone value is missing"; the prune path silently drops the entry.

Source

Thrown at kernel/av/new_item_template.go:398

		}
		if KeyTypeSelect == key.Type && 1 < len(selections) {
			selections = selections[:1]
		}
		value.MSelect = selections
		value.Text, value.Number, value.Date, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeURL:
		if nil == value.URL {
			return nil, errors.New("URL value is missing")
		}
		value.Text, value.Number, value.Date, value.MSelect, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeEmail:
		if nil == value.Email {
			return nil, errors.New("email value is missing")
		}
		value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypePhone:
		if nil == value.Phone {
			return nil, errors.New("phone value is missing")
		}
		value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeMAsset:
		var assets []*ValueAsset
		for _, asset := range value.MAsset {
			if nil != asset && "" != strings.TrimSpace(asset.Content) {
				if AssetTypeFile != asset.Type && AssetTypeImage != asset.Type {
					return nil, fmt.Errorf("invalid asset type [%s]", asset.Type)
				}
				assets = append(assets, asset)
			}
		}
		value.MAsset = assets
		value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeCheckbox:
		if nil == value.Checkbox {
			return nil, errors.New("checkbox value is missing")
		}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Include a non-null phone object in the value JSON, e.g. {"phone": {"content": "+1-555-0100"}}
  2. Omit the field from FieldValues entirely if no default phone value is needed
  3. Set Value.Phone = &ValuePhone{Content: "..."} before saving

Example fix

// before
fieldValue.Value = &av.Value{Type: av.KeyTypePhone}
// after
fieldValue.Value = &av.Value{Type: av.KeyTypePhone, Phone: &av.ValuePhone{Content: "+1-555-0100"}}
Defensive patterns

Strategy: validation

Validate before calling

func validatePhoneValue(value *av.Value, key *av.Key) error {
    if key.Type == av.KeyTypePhone && value.Phone == nil {
        return fmt.Errorf("phone key requires a non-nil Value.Phone")
    }
    return nil
}

Type guard

func hasPhoneValue(v *av.Value) bool {
    return v != nil && v.Phone != nil
}

Prevention

When it happens

Trigger: Saving an Attribute View new-item template with a static-mode field whose key type is "phone" but whose Value object lacks a non-null "phone" sub-field.

Common situations: Reusing a generic Value payload across field types in template creation; frontend deserialization that leaves optional pointers as nil; schema migration from a version without phone fields.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/6e7a38bcc8a58bd9. Report an issue: GitHub.