BoundaryML/baml · error

failed to marshal object method arguments: %w

Error message

failed to marshal object method arguments: %w

What it means

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.

Source

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

	}
	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 {
		return nil, fmt.Errorf("failed to marshal object method arguments: %w", err)
	}
	cEncodedArgs := (*C.char)(unsafe.Pointer(&encodedArgs[0]))

	cBuf := C.WrapCallObjectMethodFunction(object.Runtime(), cEncodedArgs, C.uintptr_t(len(encodedArgs)))

	content_bytes := C.GoBytes(unsafe.Pointer(cBuf.ptr), C.int32_t(cBuf.len))
	C.WrapFreeBuffer(cBuf) // Free the buffer after use
	if cBuf.len == 0 {
		return nil, fmt.Errorf("failed to call object method function")
	}
	if cBuf.ptr == nil {
		return nil, fmt.Errorf("object method function returned nil pointer")
	}

	var content_holder cffi.InvocationResponse
	err = proto.Unmarshal(content_bytes, &content_holder)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal content bytes: %w", err)

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the wrapped %w error for the underlying cause
  2. Retry the operation; transient memory pressure may resolve it
  3. Rebuild the project to ensure protobuf generated code and runtime versions match
  4. Report with the full error if reproducible
Defensive patterns

Strategy: retry

Try / catch

res, err := CallMethod(obj, "Type", nil)
if err != nil && strings.Contains(err.Error(), "marshal object method arguments") {
    res, err = CallMethod(obj, "Type", nil) // transient marshal failure
}

Prevention

When it happens

Trigger: CallMethod invoked (via destructor, Type, ListProperties, AddProperty, Property, SetType) and proto.Marshal of the invocation message fails.

Common situations: Extremely rare; corrupted protobuf runtime registration or out-of-memory conditions during marshalling.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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