{"record":{"id":"e8501dc28c5ddd94","repo":"BoundaryML/baml","slug":"failed-to-unmarshal-content-bytes-w","errorCode":null,"errorMessage":"failed to unmarshal content bytes: %w","messagePattern":"failed to unmarshal content bytes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/raw_objects/utils.go","lineNumber":133,"sourceCode":"\t}\n\tcEncodedArgs := (*C.char)(unsafe.Pointer(&encodedArgs[0]))\n\n\tcBuf := C.WrapCallObjectConstructor(cEncodedArgs, C.uintptr_t(len(encodedArgs)))\n\n\tcontent_bytes := C.GoBytes(unsafe.Pointer(cBuf.ptr), C.int32_t(cBuf.len))\n\tC.WrapFreeBuffer(cBuf) // Free the buffer after use\n\n\tif cBuf.len == 0 {\n\t\treturn nil, fmt.Errorf(\"failed to call object constructor\")\n\t}\n\tif cBuf.ptr == nil {\n\t\treturn nil, fmt.Errorf(\"object constructor returned nil pointer\")\n\t}\n\n\tvar content_holder cffi.InvocationResponse\n\terr = proto.Unmarshal(content_bytes, &content_holder)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal content bytes: %w\", err)\n\t}\n\tparsed, err := decodeObjectResponse(rt, &content_holder)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode object response: %w\", err)\n\t}\n\n\treturn parsed, nil\n}\n\nfunc destructor(object RawPointer) error {\n\tresult, err := CallMethod(object, \"~destructor\", nil)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to call destructor: %w\", err)\n\t}\n\n\tif result != nil {\n\t\treturn fmt.Errorf(\"destructor returned unexpected result: %v\", result)","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/raw_objects/utils.go#L115-L151","documentation":"This error wraps a protobuf unmarshal failure inside NewRawObject. After calling the native (Rust/C) object constructor over FFI, Go reads the returned byte buffer and tries to decode it as a cffi.InvocationResponse protobuf message; if the bytes are not a valid protobuf payload the construction fails. It indicates an FFI/IPC layer corruption or version mismatch rather than a problem with user arguments.","triggerScenarios":"Calling b.NewCollector(), b.NewTypeBuilder(), or a media constructor (newMediaFromUrl/newMediaFromBase64) when the native library returns a corrupted or incompatible byte buffer from WrapCallObjectConstructor.","commonSituations":"Mismatched BAML native library and Go bindings versions, memory corruption in the FFI bridge, or a truncated/zero-filled buffer being read after the buffer was freed incorrectly.","solutions":["Rebuild/reinstall the BAML Go bindings so the Go cffi protobuf definitions match the native library version","Check the wrapped %w error for the specific protobuf parse failure (e.g. 'proto: cannot parse invalid wire-format data')","Set BAML_FFI_CLIENT_LOG to capture FFI logs and report the issue with them","Retry the operation once to rule out transient memory corruption"],"exampleFix":"// before: mixed versions of native lib and Go module\ngo get github.com/boundaryml/baml@latest\n// after: keep go module and native lib versions in lockstep\ngo.mod: require github.com/boundaryml/baml vX.Y.Z matching baml-cli vX.Y.Z","handlingStrategy":"try-catch","validationCode":"if rt == nil { return fmt.Errorf(\"baml runtime must be initialized before creating objects\") }","typeGuard":null,"tryCatchPattern":"obj, err := b.NewCollector(rt)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to unmarshal content bytes\") {\n        // FFI/protobuf corruption: rebuild bindings or fail fast\n        return fmt.Errorf(\"baml FFI bridge corrupted: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep the BAML Go module and native library on the same version","Pin BAML versions in go.mod and CI","Set BAML_FFI_CLIENT_LOG in dev environments for diagnostics"],"tags":["go","ffi","protobuf","unmarshal"],"backgroundTag":"protobuf-unmarshal-failed","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"}