siyuan-note/siyuan · error

number value is missing

Error message

number value is missing

What it means

normalizeNewItemTemplateValue, when handling a KeyTypeNumber key, requires the Value to carry a non-nil Number payload. If value.Number is nil the value cannot represent numeric content for the field, so the sentinel error 'number value is missing' is returned and the template configuration fails.

Solutions

  1. Set Value.Number to a &av.ValueNumber with the desired Content before saving
  2. Remove the FieldValues entry if no numeric value is needed
  3. Confirm the key's Type is actually KeyTypeNumber and match the payload accordingly

Example fix

// before
fv.Value = &av.Value{Text: &av.ValueText{Content: "42"}} // number key
err := av.SetNewItemTemplates(config) // number value is missing
// after
fv.Value = &av.Value{Number: &av.ValueNumber{Content: 42}}
err := av.SetNewItemTemplates(config)
Defensive patterns

Strategy: validation

Validate before calling

if key.Type == av.KeyTypeNumber && (fv.Value == nil || fv.Value.Number == nil) {
	return fmt.Errorf("number key %s requires a Number payload", keyID)
}

Type guard

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

Prevention

When it happens

Trigger: Calling SetNewItemTemplates (static mode) — or PruneInvalidNewItemTemplateFieldValues — with a Value for a number key where the Number sub-field is nil (e.g. a Text payload was supplied instead).

Common situations: Populating Value.Text for a numeric field; reusing a value cloned from a text field; deserialized JSON where the Number payload was omitted.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at kernel/av/new_item_template.go:366

	if 0 == len(fieldValues) {
		itemTemplate.FieldValues = nil
	} else {
		itemTemplate.FieldValues = fieldValues
	}
	return nil
}

func normalizeNewItemTemplateValue(value *Value, key *Key) (*Value, error) {
	value = value.Clone()
	switch key.Type {
	case KeyTypeText:
		if nil == value.Text {
			return nil, errors.New("text value is missing")
		}
		value.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeNumber:
		if nil == value.Number {
			return nil, errors.New("number value is missing")
		}
		value.Text, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeDate:
		if nil == value.Date {
			return nil, errors.New("date value is missing")
		}
		value.Text, value.Number, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeSelect, KeyTypeMSelect:
		var selections []*ValueSelect
		for _, selection := range value.MSelect {
			if nil != selection && "" != strings.TrimSpace(selection.Content) {
				selections = append(selections, selection)
			}
		}
		if KeyTypeSelect == key.Type && 1 < len(selections) {
			selections = selections[:1]
		}
		value.MSelect = selections

View on GitHub (pinned to 9f775e8a12)