BoundaryML/baml · warning

destructor returned unexpected result: %v

Error message

destructor returned unexpected result: %v

What it means

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.

Source

Thrown at engine/language_client_go/baml_go/raw_objects/utils.go:151

		return nil, fmt.Errorf("failed to unmarshal content bytes: %w", err)
	}
	parsed, err := decodeObjectResponse(rt, &content_holder)
	if err != nil {
		return nil, fmt.Errorf("failed to decode object response: %w", err)
	}

	return parsed, nil
}

func destructor(object RawPointer) error {
	result, err := CallMethod(object, "~destructor", nil)

	if err != nil {
		return fmt.Errorf("failed to call destructor: %w", err)
	}

	if result != nil {
		return fmt.Errorf("destructor returned unexpected result: %v", result)
	}
	return nil
}

func CallMethod(object RawPointer, method_name string, kwargs map[string]any) (any, error) {
	cffi_kwargs, err := serde.EncodeMapEntries(kwargs, "function arguments")
	if err != nil {
		return nil, fmt.Errorf("encoding method arguments: %w", err)
	}

	args := cffi.BamlObjectMethodInvocation{
		Kwargs:     cffi_kwargs,
		Object:     EncodeRawObject(object),
		MethodName: method_name,
	}

	encodedArgs, err := proto.Marshal(&args)
	if err != nil {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Ensure Go bindings and native BAML library versions match (upgrade both together)
  2. Check FFI logs to identify which object type misbehaved
  3. Report to BAML maintainers with the object type and logs if versions match
Defensive patterns

Strategy: fallback

Try / catch

// surfaced only via finalizer logs; treat as library bug
// if err := destructor(obj); err != nil && strings.Contains(err.Error(), "unexpected result") { report() }

Prevention

When it happens

Trigger: GC finalizer runs on a BAML object whose native '~destructor' method unexpectedly returns a value instead of nil.

Common situations: Version mismatch between Go bindings and native library where the destructor's return semantics changed; a bug in a custom object implementation.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/59a993922f317ea3. Report an issue: GitHub.