{"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/251596fc0de2f9528c00c224252fd073a99973f4/kernel/av/new_item_template.go#L316-L352","documentation":"Wrapper around normalizeNewItemTemplateValue failures for Static-mode values. The wrapped error (%w) identifies the concrete problem: one of the per-type 'X value is missing' errors (text/number/date/URL/email/phone/checkbox/relation), 'invalid asset type', 'invalid relation block ID', or 'unsupported value type'. The field keyID prefixes the wrapped message.","triggerScenarios":"Static mode on a field whose Value sub-struct does not match the key type (e.g. key=URL but Value.URL nil); a Relation value containing a malformed block ID; an MAsset value with an unknown asset type.","commonSituations":"Client sends a partial Value with the wrong sub-field populated; type change after the template was authored; malformed import.","solutions":["Read the wrapped error — it names the specific sub-field or constraint that failed (e.g. 'URL value is missing').","Ensure the Value struct carries the sub-pointer that matches key.Type (see normalizeNewItemTemplateValue, new_item_template.go:356).","For Relation values, validate every BlockID with ast.IsNodeIDPattern before submitting."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-normalize one value to surface the inner error early.\nif _, err := normalizeNewItemTemplateValue(value, key); err != nil {\n    return fmt.Errorf(\"field [%s] value is invalid: %w\", keyID, err)\n}","typeGuard":null,"tryCatchPattern":"err := av.SetNewItemTemplates(config)\nif err != nil && strings.Contains(err.Error(), \"value is invalid\") {\n    // inspect err for the wrapped cause (missing sub-field, bad relation ID, etc.)\n    return err\n}","preventionTips":["Read the wrapped error to find the exact sub-field that failed.","Populate the Value sub-pointer that matches key.Type exactly.","For Relation values, validate every BlockID with ast.IsNodeIDPattern first."],"tags":["av","new-item-template","value","validation","wrapper"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}