{"record":{"id":"a22d2c0b4a2f08da","repo":"siyuan-note/siyuan","slug":"text-value-is-missing","errorCode":null,"errorMessage":"text value is missing","messagePattern":"text value is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":361,"sourceCode":"\t\tdefault:\n\t\t\treturn fmt.Errorf(\"invalid new item template field value mode [%s]\", fieldValue.Mode)\n\t\t}\n\t\tfieldValues[keyID] = fieldValue\n\t}\n\tif 0 == len(fieldValues) {\n\t\titemTemplate.FieldValues = nil\n\t} else {\n\t\titemTemplate.FieldValues = fieldValues\n\t}\n\treturn nil\n}\n\nfunc normalizeNewItemTemplateValue(value *Value, key *Key) (*Value, error) {\n\tvalue = value.Clone()\n\tswitch key.Type {\n\tcase KeyTypeText:\n\t\tif nil == value.Text {\n\t\t\treturn nil, errors.New(\"text value is missing\")\n\t\t}\n\t\tvalue.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\n\tcase KeyTypeNumber:\n\t\tif nil == value.Number {\n\t\t\treturn nil, errors.New(\"number value is missing\")\n\t\t}\n\t\tvalue.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\n\tcase KeyTypeDate:\n\t\tif nil == value.Date {\n\t\t\treturn nil, errors.New(\"date value is missing\")\n\t\t}\n\t\tvalue.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\n\tcase KeyTypeSelect, KeyTypeMSelect:\n\t\tvar selections []*ValueSelect\n\t\tfor _, selection := range value.MSelect {\n\t\t\tif nil != selection && \"\" != strings.TrimSpace(selection.Content) {\n\t\t\t\tselections = append(selections, selection)\n\t\t\t}","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L343-L379","documentation":"normalizeNewItemTemplateValue, when handling a KeyTypeText key, requires the Value to carry a non-nil Text payload. A cloned Value with value.Text == nil cannot represent text content, so it returns the sentinel error 'text value is missing', which callers wrap or surface when pruning invalid field values.","triggerScenarios":"Calling SetNewItemTemplates (static mode) — or PruneInvalidNewItemTemplateFieldValues — with a Value for a text key where the Text sub-field is nil while some other sub-field (Number, Date, etc.) may be populated instead.","commonSituations":"Reusing a Value object taken from a number or date field for a text key; constructing &av.Value{} without setting Text; JSON deserialization dropping the Text payload.","solutions":["Set Value.Text to a &av.ValueText with the desired Content before saving","Remove the FieldValues entry if no text value is needed","Verify the key's Type matches the payload you are filling"],"exampleFix":"// before\nfv.Value = &av.Value{Number: &av.ValueNumber{Content: 1}} // text key\nerr := av.SetNewItemTemplates(config) // text value is missing\n// after\nfv.Value = &av.Value{Text: &av.ValueText{Content: \"1\"}}\nerr := av.SetNewItemTemplates(config)","handlingStrategy":"validation","validationCode":"if key.Type == av.KeyTypeText && (fv.Value == nil || fv.Value.Text == nil) {\n\treturn fmt.Errorf(\"text key %s requires a Text payload\", keyID)\n}","typeGuard":"func hasTextPayload(v *av.Value) bool { return v != nil && v.Text != nil }","tryCatchPattern":null,"preventionTips":["Match the Value sub-field to the key type before assigning it","Run PruneInvalidNewItemTemplateFieldValues to drop unusable values instead of failing the whole config"],"tags":["attribute-view","validation","value-shape"],"backgroundTag":"invalid-argument-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}