{"record":{"id":"59a993922f317ea3","repo":"BoundaryML/baml","slug":"destructor-returned-unexpected-result-v","errorCode":null,"errorMessage":"destructor returned unexpected result: %v","messagePattern":"destructor returned unexpected result: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"engine/language_client_go/baml_go/raw_objects/utils.go","lineNumber":151,"sourceCode":"\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)\n\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 {","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/raw_objects/utils.go#L133-L169","documentation":"This error is thrown when the '~destructor' FFI method returns a non-nil result; the destructor protocol requires it to return nothing. A non-nil return means the native side violated the destructor contract, signaling a bug or protocol mismatch in the FFI bridge.","triggerScenarios":"GC finalizer runs on a BAML object whose native '~destructor' method unexpectedly returns a value instead of nil.","commonSituations":"Version mismatch between Go bindings and native library where the destructor's return semantics changed; a bug in a custom object implementation.","solutions":["Ensure Go bindings and native BAML library versions match (upgrade both together)","Check FFI logs to identify which object type misbehaved","Report to BAML maintainers with the object type and logs if versions match"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// surfaced only via finalizer logs; treat as library bug\n// if err := destructor(obj); err != nil && strings.Contains(err.Error(), \"unexpected result\") { report() }","preventionTips":["Upgrade Go bindings and native library together","Report occurrences with object type and FFI logs","Do not implement custom destructors returning values"],"tags":["go","ffi","destructor","protocol"],"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"}