siyuan-note/siyuan · error
new item template field
Error message
new item template field [%s] value is invalid: %w
What it means
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.
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
Example fix
// before
fv.Value = &av.Value{} // text key but Text payload missing
err := av.SetNewItemTemplates(config) // value is invalid: text value is missing
// after
fv.Value = &av.Value{Text: &av.ValueText{Content: "hello"}}
err := av.SetNewItemTemplates(config) Defensive patterns
Strategy: validation
Validate before calling
if fv.Value != nil {
if _, err := normalizeNewItemTemplateValue(fv.Value, key); err != nil {
return fmt.Errorf("field %s: %w", keyID, err)
}
} Type guard
func validStaticValue(v *av.Value, key *av.Key) bool {
if v == nil { return true }
switch key.Type {
case av.KeyTypeText: return v.Text != nil
case av.KeyTypeNumber: return v.Number != nil
case av.KeyTypeDate: return v.Date != nil
default: return true
}
} Try / catch
if err := av.SetNewItemTemplates(config); err != nil {
var cause string
if i := strings.Index(err.Error(), ": "); i >= 0 { cause = err.Error()[i+2:] }
log.Printf("invalid template field value, cause: %s", cause)
} Prevention
- Fill exactly the sub-field matching the key type on Value
- Construct values with dedicated constructors per key type instead of empty structs
When it happens
Trigger: 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.
Common situations: 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.
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
- number value is missing
- text value is missing
- at least one visible view is required
- attribute view custom color index
- attribute view custom color must not be null
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/54b18734aa37387f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/new_item_template.go:334
if nil == fieldValue {
continue
}
if "" == fieldValue.Mode {
fieldValue.Mode = NewItemFieldValueStatic
}
switch fieldValue.Mode {
case NewItemFieldValueCurrentTime:
if KeyTypeDate != key.Type {
return fmt.Errorf("new item template field [%s] current time mode requires date type", keyID)
}
fieldValue.Value = nil
case NewItemFieldValueStatic:
if nil == fieldValue.Value {
continue
}
fieldValue.Value, err = normalizeNewItemTemplateValue(fieldValue.Value, key)
if nil != err {
return fmt.Errorf("new item template field [%s] value is invalid: %w", keyID, err)
}
if KeyTypeSelect == key.Type || KeyTypeMSelect == key.Type {
for _, selection := range fieldValue.Value.MSelect {
if nil != selection && nil == key.GetOption(selection.Content) {
return fmt.Errorf("new item template field [%s] option [%s] not found", keyID, selection.Content)
}
}
}
default:
return fmt.Errorf("invalid new item template field value mode [%s]", fieldValue.Mode)
}
fieldValues[keyID] = fieldValue
}
if 0 == len(fieldValues) {
itemTemplate.FieldValues = nil
} else {
itemTemplate.FieldValues = fieldValues
}View on GitHub (pinned to 9f775e8a12)