BoundaryML/baml · error
failed to create collector
Error message
failed to create collector: %w
What it means
Wraps errors from raw_objects.NewRawObject when constructing the OBJECT_COLLECTOR in BamlRuntime.NewCollector (rawobjects_constructors.go:22). The native runtime refused or failed to create the collector object from the encoded kwargs.
Solutions
- Read the wrapped NewRawObject error for the runtime-side cause.
- Use a unique collector name and valid kwargs.
- Reinstall matched BAML Go client + native binaries and retry.
Example fix
// before
collector, _ := rt.NewCollector("run-1")
// after
collector, err := rt.NewCollector("run-1")
if err != nil {
return nil, fmt.Errorf("collector init failed: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if rt == nil { return errors.New("runtime not initialized") }
if strings.TrimSpace(name) == "" { return errors.New("collector name required") } Try / catch
collector, err := rt.NewCollector(name)
if err != nil {
var root error = err
for errors.Unwrap(root) != nil { root = errors.Unwrap(root) }
return fmt.Errorf("collector creation failed (%v): %w", root, err)
} Prevention
- Use unique collector names per run.
- Create collectors before workload execution, not during shutdown.
- Reinstall matched BAML binaries if construction fails consistently.
When it happens
Trigger: BamlRuntime.NewCollector(name) where the C++ runtime's collector construction fails — e.g. duplicate collector name at runtime, invalid kwargs, or runtime-side construction panic surfaced through FFI.
Common situations: Runtime rejecting constructor args after a version upgrade; creating collectors during runtime shutdown; native binary incompatibility.
Related errors
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/139cc2e7ad0e2685.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_client_go/pkg/rawobjects_constructors.go:22
"fmt"
"github.com/boundaryml/baml/engine/language_client_go/baml_go/raw_objects"
"github.com/boundaryml/baml/engine/language_client_go/baml_go/serde"
"github.com/boundaryml/baml/engine/language_client_go/pkg/cffi"
)
// / Construct Collector
func (r *BamlRuntime) NewCollector(name string) (Collector, error) {
kwargs, err := serde.EncodeMapEntries(map[string]any{
"name": name,
}, "collector constructor args")
if err != nil {
return nil, fmt.Errorf("failed to encode kwargs: %w", err)
}
ptr, err := raw_objects.NewRawObject(r.runtime, cffi.BamlObjectType_OBJECT_COLLECTOR, kwargs)
if err != nil {
return nil, fmt.Errorf("failed to create collector: %w", err)
}
as_collector, ok := ptr.(*collector)
if !ok {
return nil, fmt.Errorf("unexpected type for collector creation: %T", ptr)
}
return as_collector, nil
}
func (r *BamlRuntime) newMediaFromUrl(mediaType MediaType, url string, mimeType *string) (media, error) {
kwargs, err := serde.EncodeMapEntries(map[string]any{
"mime_type": mimeType,
"url": url,
}, "media constructor args")
if err != nil {
return nil, fmt.Errorf("failed to encode kwargs: %w", err)
}View on GitHub (pinned to bd85ce9dee)