{"record":{"id":"11b1f0a8d045cd6c","repo":"BoundaryML/baml","slug":"failed-to-marshal-object-method-arguments-w","errorCode":null,"errorMessage":"failed to marshal object method arguments: %w","messagePattern":"failed to marshal object method arguments: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/raw_objects/utils.go","lineNumber":170,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc CallMethod(object RawPointer, method_name string, kwargs map[string]any) (any, error) {\n\tcffi_kwargs, err := serde.EncodeMapEntries(kwargs, \"function arguments\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"encoding method arguments: %w\", err)\n\t}\n\n\targs := cffi.BamlObjectMethodInvocation{\n\t\tKwargs:     cffi_kwargs,\n\t\tObject:     EncodeRawObject(object),\n\t\tMethodName: method_name,\n\t}\n\n\tencodedArgs, err := proto.Marshal(&args)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal object method arguments: %w\", err)\n\t}\n\tcEncodedArgs := (*C.char)(unsafe.Pointer(&encodedArgs[0]))\n\n\tcBuf := C.WrapCallObjectMethodFunction(object.Runtime(), 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\tif cBuf.len == 0 {\n\t\treturn nil, fmt.Errorf(\"failed to call object method function\")\n\t}\n\tif cBuf.ptr == nil {\n\t\treturn nil, fmt.Errorf(\"object method function 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)","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/raw_objects/utils.go#L152-L188","documentation":"This error wraps a proto.Marshal failure of the BamlObjectMethodInvocation message inside CallMethod. Protobuf marshalling of a struct with only standard proto fields essentially never fails in practice; if it does, it indicates memory pressure or a corrupted proto registry.","triggerScenarios":"CallMethod invoked (via destructor, Type, ListProperties, AddProperty, Property, SetType) and proto.Marshal of the invocation message fails.","commonSituations":"Extremely rare; corrupted protobuf runtime registration or out-of-memory conditions during marshalling.","solutions":["Read the wrapped %w error for the underlying cause","Retry the operation; transient memory pressure may resolve it","Rebuild the project to ensure protobuf generated code and runtime versions match","Report with the full error if reproducible"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"res, err := CallMethod(obj, \"Type\", nil)\nif err != nil && strings.Contains(err.Error(), \"marshal object method arguments\") {\n    res, err = CallMethod(obj, \"Type\", nil) // transient marshal failure\n}","preventionTips":["Keep protobuf generated code and runtime versions aligned via go.mod","Retry transient marshal failures once","Report persistent failures with the wrapped cause"],"tags":["go","protobuf","marshal","ffi"],"backgroundTag":"json-marshal-failed","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"}