BoundaryML/baml · error

failed to get ID

Error message

failed to get ID: %w

What it means

functionLog.Id() invokes the runtime's 'id' method on the underlying FunctionLog raw object and wraps any FFI failure with this message. It means the host-side call to retrieve the log's unique ID failed (as opposed to the ID having an unexpected Go type, which yields a separate error).

Solutions

  1. Read Id() promptly, within the same lifecycle as the FunctionLog event/callback
  2. Verify the runtime hasn't been shut down (Finish/Close) before calling Id()
  3. Re-obtain the FunctionLog via runtime.GetFunctionLog(id or name) if the original handle is stale
  4. Check callback code paths keep a Go reference to the log object until Id() is read

Example fix

// before
onEvent := func(fl FunctionLog, ev BamlError) {
    go func() { time.Sleep(1 * time.Hour); id, _ := fl.Id() }() // handle may be gone
}
// after
onEvent := func(fl FunctionLog, ev BamlError) {
    id, err := fl.Id() // read synchronously while handle is valid
    if err != nil { log.Printf("function log id: %v", err) }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// guard: only call Id() while the runtime is alive and the log is fresh
select {
case <-runtimeDone:
    return errors.New("runtime already shut down")
default:
}

Try / catch

id, err := fnLog.Id()
if err != nil {
    if strings.Contains(err.Error(), "failed to get ID") {
        // handle stale: re-fetch log via runtime.GetFunctionLog or skip
    }
    return err
}

Prevention

When it happens

Trigger: Calling Id() on a FunctionLog obtained from a callback/stream event or GetFunctionLog after the underlying raw object became invalid — e.g. the log handle was already consumed or the runtime was shut down.

Common situations: Storing FunctionLog objects and reading Id() after the runtime was closed; accessing Id() inside on_event callbacks on a freed handle; mixed binding/runtime versions corrupting method dispatch.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

	*raw_objects.RawObject
}

func newFunctionLog(ptr int64, rt unsafe.Pointer) FunctionLog {
	return &functionLog{raw_objects.FromPointer(ptr, rt)}
}

func (f *functionLog) ObjectType() cffi.BamlObjectType {
	return cffi.BamlObjectType_OBJECT_FUNCTION_LOG
}

func (f *functionLog) pointer() int64 {
	return f.RawObject.Pointer()
}

func (f *functionLog) Id() (string, error) {
	result, err := raw_objects.CallMethod(f, "id", nil)
	if err != nil {
		return "", fmt.Errorf("failed to get ID: %w", err)
	}

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

	return id, nil
}

func (f *functionLog) FunctionName() (string, error) {
	result, err := raw_objects.CallMethod(f, "function_name", nil)
	if err != nil {
		return "", fmt.Errorf("failed to get function name: %w", err)
	}

	name, ok := result.(string)
	if !ok {

View on GitHub (pinned to bd85ce9dee)