BoundaryML/baml · error

failed to get text: %w

Error message

failed to get text: %w

What it means

This error wraps any failure from the FFI call to the runtime's `text` method on an SSE response object. Text() retrieves the streamed text payload from the native runtime; if that remote call fails, the cause is preserved via %w. It is a transport/FFI-level failure, not a content problem.

Source

Thrown at engine/language_client_go/pkg/rawobjects_sse_response.go:30

	*raw_objects.RawObject
}

func newSSEResponse(ptr int64, rt unsafe.Pointer) SSEResponse {
	return &sseResponse{raw_objects.FromPointer(ptr, rt)}
}

func (s *sseResponse) ObjectType() cffi.BamlObjectType {
	return cffi.BamlObjectType_OBJECT_SSE_RESPONSE
}

func (s *sseResponse) pointer() int64 {
	return s.RawObject.Pointer()
}

func (s *sseResponse) Text() (string, error) {
	result, err := raw_objects.CallMethod(s, "text", nil)
	if err != nil {
		return "", fmt.Errorf("failed to get text: %w", err)
	}

	text, ok := result.(string)
	if !ok {
		return "", fmt.Errorf("unexpected type for text: %T", result)
	}

	return text, nil
}

func (s *sseResponse) JSON() (any, error) {
	result, err := raw_objects.CallMethod(s, "json", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get JSON: %w", err)
	}

	return result, nil
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Inspect errors.Unwrap(err) for the underlying FFI cause
  2. Consume the SSE response promptly within the stream's lifetime; do not cache handles across requests
  3. Re-run the BAML streaming call to obtain a fresh response object
  4. Align the Go module and native runtime versions
Defensive patterns

Strategy: try-catch

Validate before calling

if sseResp == nil { return fmt.Errorf("sse response is nil") }

Try / catch

text, err := sseResp.Text()
if err != nil {
    log.Printf("sse text unavailable: %v (cause: %v)", err, errors.Unwrap(err))
    return restartStream(ctx)
}

Prevention

When it happens

Trigger: Calling Text() on an SseResponse whose raw object handle is stale or freed, or whose runtime-side `text` method errors while extracting the streamed payload.

Common situations: Accessing the SSE response after the stream finished and the object was released; client/runtime version skew; interrupted stream leaving the runtime object in a bad state.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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