{"record":{"id":"884a0a35c4327136","repo":"BoundaryML/baml","slug":"failed-to-decode-object-at-index-d-w","errorCode":null,"errorMessage":"failed to decode object at index %d: %w","messagePattern":"failed to decode object at index (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/raw_objects/utils.go","lineNumber":223,"sourceCode":"\t\treturn nil, fmt.Errorf(\"nil response\")\n\t}\n\n\tswitch response.GetResponse().(type) {\n\tcase *cffi.InvocationResponse_Error:\n\t\treturn nil, fmt.Errorf(\"%s\", response.GetError())\n\tcase *cffi.InvocationResponse_Success:\n\t\tsuccess := response.GetSuccess()\n\t\tswitch success.Result.(type) {\n\t\tcase *cffi.InvocationResponseSuccess_Object:\n\t\t\tobject := success.GetObject()\n\t\t\treturn decodeRawObject(rt, object)\n\t\tcase *cffi.InvocationResponseSuccess_Objects:\n\t\t\tobjects := success.GetObjects()\n\t\t\tparsed := make([]RawPointer, len(objects.Objects))\n\t\t\tfor i, obj := range objects.Objects {\n\t\t\t\tdecoded, err := decodeRawObject(rt, obj)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to decode object at index %d: %w\", i, err)\n\t\t\t\t}\n\t\t\t\tparsed[i] = decoded\n\t\t\t}\n\t\t\treturn parsed, nil\n\t\tcase *cffi.InvocationResponseSuccess_Value:\n\t\t\tvalue := success.GetValue()\n\t\t\tnilType := reflect.TypeOf((*nilObject)(nil)).Elem()\n\t\t\tdecodedValue, goType := serde.Decode(value, serde.NewInternalTypeMap(map[string]reflect.Type{\n\t\t\t\t\"INTERNAL.nil\": nilType,\n\t\t\t}))\n\t\t\tif goType == nilType {\n\t\t\t\treturn nil, nil\n\t\t\t}\n\t\t\treturn decodedValue.Interface(), nil\n\t\tdefault:\n\t\t\tpanic(\"unexpected cffi.isCFFIObjectResponseSuccess_Result\")\n\t\t}\n\tdefault:","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/raw_objects/utils.go#L205-L241","documentation":"When the FFI response contains multiple objects (InvocationResponseSuccess_Objects), each is decoded with decodeRawObject; if any element fails, the whole decode fails with this message naming the failing index and the wrapped cause. It indicates one element of a multi-object result could not be converted into a Go RawPointer.","triggerScenarios":"CallMethod or NewRawObject returning a batch of objects where decodeRawObject fails for element i — typically a nil or invalid BamlObjectHandle for that element.","commonSituations":"Native runtime returned a partially invalid object list, null entries inside the objects array, or a handle pointing to a type with no registered Go decoder.","solutions":["Inspect the wrapped %w cause for the actual per-object decode failure","Log the response objects to find which index is nil or malformed","Regenerate/upgrade baml_client if a new object type lacks a decoder","Report a repro to BAML maintainers if the native side returns nil elements unexpectedly"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"parsed, err := decodeObjectResponse(rt, resp)\nif err != nil {\n  var idxErr *IndexDecodeError\n  if errors.As(err, &idxErr) { log.Printf(\"failed at object %d\", idxErr.Index) }\n  return err\n}","preventionTips":["Inspect the wrapped cause (%w) to identify the failing element","Keep runtime and bindings in sync to avoid malformed object lists","Log full responses when debugging batch decodes"],"tags":["go","ffi","decoding","batch"],"backgroundTag":"unexpected-response-shape","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}