{"record":{"id":"54b18734aa37387f","repo":"siyuan-note/siyuan","slug":"new-item-template-field-s-value-is-invalid-w","errorCode":null,"errorMessage":"new item template field [%s] value is invalid: %w","messagePattern":"new item template field \\[(.+?)\\] value is invalid: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":334,"sourceCode":"\t\tif nil == fieldValue {\n\t\t\tcontinue\n\t\t}\n\t\tif \"\" == fieldValue.Mode {\n\t\t\tfieldValue.Mode = NewItemFieldValueStatic\n\t\t}\n\t\tswitch fieldValue.Mode {\n\t\tcase NewItemFieldValueCurrentTime:\n\t\t\tif KeyTypeDate != key.Type {\n\t\t\t\treturn fmt.Errorf(\"new item template field [%s] current time mode requires date type\", keyID)\n\t\t\t}\n\t\t\tfieldValue.Value = nil\n\t\tcase NewItemFieldValueStatic:\n\t\t\tif nil == fieldValue.Value {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfieldValue.Value, err = normalizeNewItemTemplateValue(fieldValue.Value, key)\n\t\t\tif nil != err {\n\t\t\t\treturn fmt.Errorf(\"new item template field [%s] value is invalid: %w\", keyID, err)\n\t\t\t}\n\t\t\tif KeyTypeSelect == key.Type || KeyTypeMSelect == key.Type {\n\t\t\t\tfor _, selection := range fieldValue.Value.MSelect {\n\t\t\t\t\tif nil != selection && nil == key.GetOption(selection.Content) {\n\t\t\t\t\t\treturn fmt.Errorf(\"new item template field [%s] option [%s] not found\", keyID, selection.Content)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\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}","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L316-L352","documentation":"For static-mode field values, normalizeNewItemTemplateValue coerces the supplied Value into the shape required by the key's type, nulling out all unrelated sub-values. If that normalization returns an error (e.g. the type-specific payload such as Text/Number/Date is nil, or a nested value is malformed), the error is wrapped as 'new item template field [%s] value is invalid' and the configuration is rejected.","triggerScenarios":"Calling SetNewItemTemplates with a static FieldValues entry whose Value lacks the payload for the key's type (e.g. Value.Text == nil for a text key), contains an invalid asset type, or has an invalid relation block ID; the underlying cause is appended via %w.","commonSituations":"Building a Value struct programmatically but filling the wrong sub-field for the key type; deserializing values from JSON where the payload was dropped; reusing a Value captured from a different-typed field.","solutions":["Read the wrapped cause after the colon in the error message to identify the missing/invalid payload","Populate the correct sub-field on Value for the key's type (Text for KeyTypeText, Number for KeyTypeNumber, Date for KeyTypeDate, etc.)","Remove the FieldValues entry if no valid static value can be provided"],"exampleFix":"// before\nfv.Value = &av.Value{} // text key but Text payload missing\nerr := av.SetNewItemTemplates(config) // value is invalid: text value is missing\n// after\nfv.Value = &av.Value{Text: &av.ValueText{Content: \"hello\"}}\nerr := av.SetNewItemTemplates(config)","handlingStrategy":"validation","validationCode":"if fv.Value != nil {\n\tif _, err := normalizeNewItemTemplateValue(fv.Value, key); err != nil {\n\t\treturn fmt.Errorf(\"field %s: %w\", keyID, err)\n\t}\n}","typeGuard":"func validStaticValue(v *av.Value, key *av.Key) bool {\n\tif v == nil { return true }\n\tswitch key.Type {\n\tcase av.KeyTypeText: return v.Text != nil\n\tcase av.KeyTypeNumber: return v.Number != nil\n\tcase av.KeyTypeDate: return v.Date != nil\n\tdefault: return true\n\t}\n}","tryCatchPattern":"if err := av.SetNewItemTemplates(config); err != nil {\n\tvar cause string\n\tif i := strings.Index(err.Error(), \": \"); i >= 0 { cause = err.Error()[i+2:] }\n\tlog.Printf(\"invalid template field value, cause: %s\", cause)\n}","preventionTips":["Fill exactly the sub-field matching the key type on Value","Construct values with dedicated constructors per key type instead of empty structs"],"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"}