{"record":{"id":"3869d38821e82c0e","repo":"siyuan-note/siyuan","slug":"email-value-is-missing","errorCode":null,"errorMessage":"email value is missing","messagePattern":"email value is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":393,"sourceCode":"\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}\n\t\t}\n\t\tif KeyTypeSelect == key.Type && 1 < len(selections) {\n\t\t\tselections = selections[:1]\n\t\t}\n\t\tvalue.MSelect = selections\n\t\tvalue.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\n\tcase KeyTypeURL:\n\t\tif nil == value.URL {\n\t\t\treturn nil, errors.New(\"URL value is missing\")\n\t\t}\n\t\tvalue.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\n\tcase KeyTypeEmail:\n\t\tif nil == value.Email {\n\t\t\treturn nil, errors.New(\"email value is missing\")\n\t\t}\n\t\tvalue.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\n\tcase KeyTypePhone:\n\t\tif nil == value.Phone {\n\t\t\treturn nil, errors.New(\"phone value is missing\")\n\t\t}\n\t\tvalue.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\n\tcase KeyTypeMAsset:\n\t\tvar assets []*ValueAsset\n\t\tfor _, asset := range value.MAsset {\n\t\t\tif nil != asset && \"\" != strings.TrimSpace(asset.Content) {\n\t\t\t\tif AssetTypeFile != asset.Type && AssetTypeImage != asset.Type {\n\t\t\t\t\treturn nil, fmt.Errorf(\"invalid asset type [%s]\", asset.Type)\n\t\t\t\t}\n\t\t\t\tassets = append(assets, asset)\n\t\t\t}\n\t\t}\n\t\tvalue.MAsset = assets","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L375-L411","documentation":"When the key type is KeyTypeEmail, the value must carry a non-nil Value.Email object; otherwise normalization fails with 'email value is missing'. The function rejects the value so invalid template data never reaches the attribute view.","triggerScenarios":"A value passed through PruneInvalidNewItemTemplateFieldValues or normalizeNewItemTemplateFieldValues with KeyTypeEmail and Value.Email == nil (email sub-object omitted from the JSON).","commonSituations":"Copy-pasting a URL/text template value and switching the type to email without adding the email object; API consumers assuming the email content lives in Value.Text.","solutions":["Add the email object: {\"email\":{\"content\":\"user@example.com\"}}","Use the text type if the content is not a real email field","Drop the value so pruning silently removes it","Validate Value.Email != nil for every email-typed value before calling"],"exampleFix":"// before\n{\"type\":\"email\"}\n// after\n{\"type\":\"email\",\"email\":{\"content\":\"user@example.com\"}}","handlingStrategy":"validation","validationCode":"if v.Type == av.KeyTypeEmail && v.Email == nil {\n    return fmt.Errorf(\"email value requires an email object\")\n}","typeGuard":"func hasEmail(v *av.Value) bool { return v != nil && v.Type == av.KeyTypeEmail && v.Email != nil }","tryCatchPattern":null,"preventionTips":["Put the address in Value.Email.Content, never Value.Text","Validate each typed field's payload before normalization","Test templates end-to-end through PruneInvalidNewItemTemplateFieldValues"],"tags":["attribute-view","validation","nil-value"],"backgroundTag":"null-argument","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"}