{"record":{"id":"b5826604cf8d5e45","repo":"BoundaryML/baml","slug":"encoding-list-w","errorCode":null,"errorMessage":"encoding list: %w","messagePattern":"encoding list: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/serde/encode.go","lineNumber":165,"sourceCode":"\n\tcase reflect.Float32, reflect.Float64:\n\t\treturn &cffi.HostValue{\n\t\t\tValue: &cffi.HostValue_FloatValue{\n\t\t\t\tFloatValue: rv.Float(),\n\t\t\t},\n\t\t}, nil\n\n\tcase reflect.Bool:\n\t\treturn &cffi.HostValue{\n\t\t\tValue: &cffi.HostValue_BoolValue{\n\t\t\t\tBoolValue: rv.Bool(),\n\t\t\t},\n\t\t}, nil\n\n\tcase reflect.Slice, reflect.Array:\n\t\tencoded, err := encodeList(rv)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"encoding list: %w\", err)\n\t\t}\n\t\treturn &cffi.HostValue{\n\t\t\tValue: &cffi.HostValue_ListValue{\n\t\t\t\tListValue: encoded,\n\t\t\t},\n\t\t}, nil\n\n\tcase reflect.Map:\n\t\tif rv.Type().Key().Kind() != reflect.String {\n\t\t\treturn nil, fmt.Errorf(\"map key type must be string, got %s\", rv.Type().Key().Kind())\n\t\t}\n\n\t\tencoded, err := encodeMap(rv)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"encoding map: %w\", err)\n\t\t}\n\t\treturn &cffi.HostValue{\n\t\t\tValue: &cffi.HostValue_MapValue{","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/serde/encode.go#L147-L183","documentation":"A slice or array being encoded as a baml function input contained an element that failed to encode; the element error is wrapped with 'encoding list: %w' as it bubbles out of encodeValue. This is a contextual wrapper, not a root cause — the inner error identifies the bad element.","triggerScenarios":"Passing a Go slice/array as a baml function argument (or as a class field) where at least one element is of a type the encoder cannot handle (e.g. a nested struct without a serializer, a Checked value, or an unsupported kind).","commonSituations":"Lists containing nested custom structs missing BamlSerializer implementations; lists of interfaces holding unsupported dynamic types; media objects inside lists failing their own Encode.","solutions":["Read the innermost wrapped error to find which element/type failed","Ensure list elements are primitives, maps, or types with BamlSerializer/InternalBamlSerializer implementations","Implement or register a serializer for custom element types","Convert unsupported elements to supported representations before the call"],"exampleFix":"// before\nitems := []any{myStruct{}} // struct has no serializer\nb.Fn(ctx, items)\n// after\nitems := []any{map[string]any{\"a\": 1}}\nb.Fn(ctx, items)","handlingStrategy":"validation","validationCode":"func encodableList(xs []any) bool { for _, x := range xs { if !isEncodable(x) { return false } }; return true }","typeGuard":"func isEncodable(v any) bool {\n  switch v.(type) { case string, int, int64, float64, bool, nil: return true }\n  rv := reflect.ValueOf(v)\n  switch rv.Kind() { case reflect.Slice, reflect.Array, reflect.Map: return true }\n  return false\n}","tryCatchPattern":"if err := b.Fn(ctx, items); err != nil {\n  if strings.Contains(err.Error(), \"encoding list element\") { /* log index and sanitize list */ }\n}","preventionTips":["Pre-validate list element types before baml calls","Normalize heterogeneous lists into supported types","Add serializers for custom element types used repeatedly"],"tags":["go","serialization","list","baml"],"backgroundTag":"invalid-argument-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}