BoundaryML/baml · error

failed to get last log

Error message

failed to get last log: %w

What it means

Wraps any error returned by CallMethod(c, "last") in Collector.Last() (rawobjects_collector.go:81). The underlying FFI call to the native collector's 'last' method failed — e.g. the raw object handle is invalid or the runtime reported an error.

Solutions

  1. Check err chain (errors.Unwrap) for the root FFI/runtime cause.
  2. Verify the collector was created by the same live runtime instance.
  3. Handle nil result: Last() returns (nil, nil) for an empty collector — check before use.
  4. Upgrade/reinstall matching BAML client + native binaries.

Example fix

// before
log, _ := collector.Last()
fmt.Println(log)
// after
log, err := collector.Last()
if err != nil {
	return err
}
if log == nil {
	return nil // collector is empty
}
Defensive patterns

Strategy: try-catch

Validate before calling

if collector == nil { return errors.New("collector not initialized") }

Type guard

func lastLogOrNil(c baml.Collector) baml.FunctionLog {
	l, err := c.Last()
	if err != nil || l == nil { return nil }
	return l
}

Try / catch

log, err := collector.Last()
if err != nil {
	return fmt.Errorf("collector.Last failed: %w", err)
}
if log == nil { /* empty collector: no logs yet */ }

Prevention

When it happens

Trigger: Calling collector.Last() when the native runtime call fails: invalid/stale collector pointer, runtime panic surfaced through FFI, or runtime-side 'last' error (e.g. no logs in a misconfigured collector).

Common situations: Using a Collector after the BAML runtime was torn down; FFI marshalling failures; runtime errors from calling last() on an empty collector in some runtime versions.

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/ad0cc36cccbeb415. Report an issue: GitHub.

Appendix: source

Thrown at engine/language_client_go/pkg/rawobjects_collector.go:81

		return nil, fmt.Errorf("unexpected type for logs: %T", result)
	}

	functionLogs := make([]FunctionLog, len(logs))
	for i, log := range logs {
		cast, ok := log.(FunctionLog)
		if !ok {
			return nil, fmt.Errorf("unexpected type in logs: %T", log)
		}
		functionLogs[i] = cast
	}

	return functionLogs, nil
}

func (c *collector) Last() (FunctionLog, error) {
	result, err := raw_objects.CallMethod(c, "last", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get last log: %w", err)
	}

	if result == nil {
		return nil, nil
	}

	log, ok := result.(FunctionLog)
	if !ok {
		return nil, fmt.Errorf("unexpected type for last log: %T %v", result, result)
	}

	return log, nil
}

func (c *collector) Id(functionId string) (FunctionLog, error) {
	result, err := raw_objects.CallMethod(c, "id", map[string]any{
		"id": functionId,
	})

View on GitHub (pinned to bd85ce9dee)