{"record":{"id":"139cc2e7ad0e2685","repo":"BoundaryML/baml","slug":"failed-to-create-collector-w","errorCode":null,"errorMessage":"failed to create collector: %w","messagePattern":"failed to create collector: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_constructors.go","lineNumber":22,"sourceCode":"\t\"fmt\"\n\n\t\"github.com/boundaryml/baml/engine/language_client_go/baml_go/raw_objects\"\n\t\"github.com/boundaryml/baml/engine/language_client_go/baml_go/serde\"\n\t\"github.com/boundaryml/baml/engine/language_client_go/pkg/cffi\"\n)\n\n// / Construct Collector\nfunc (r *BamlRuntime) NewCollector(name string) (Collector, error) {\n\tkwargs, err := serde.EncodeMapEntries(map[string]any{\n\t\t\"name\": name,\n\t}, \"collector constructor args\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to encode kwargs: %w\", err)\n\t}\n\n\tptr, err := raw_objects.NewRawObject(r.runtime, cffi.BamlObjectType_OBJECT_COLLECTOR, kwargs)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create collector: %w\", err)\n\t}\n\n\tas_collector, ok := ptr.(*collector)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for collector creation: %T\", ptr)\n\t}\n\n\treturn as_collector, nil\n}\n\nfunc (r *BamlRuntime) newMediaFromUrl(mediaType MediaType, url string, mimeType *string) (media, error) {\n\tkwargs, err := serde.EncodeMapEntries(map[string]any{\n\t\t\"mime_type\": mimeType,\n\t\t\"url\":       url,\n\t}, \"media constructor args\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to encode kwargs: %w\", err)\n\t}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_constructors.go#L4-L40","documentation":"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.","triggerScenarios":"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.","commonSituations":"Runtime rejecting constructor args after a version upgrade; creating collectors during runtime shutdown; native binary incompatibility.","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."],"exampleFix":"// before\ncollector, _ := rt.NewCollector(\"run-1\")\n// after\ncollector, err := rt.NewCollector(\"run-1\")\nif err != nil {\n\treturn nil, fmt.Errorf(\"collector init failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if rt == nil { return errors.New(\"runtime not initialized\") }\nif strings.TrimSpace(name) == \"\" { return errors.New(\"collector name required\") }","typeGuard":null,"tryCatchPattern":"collector, err := rt.NewCollector(name)\nif err != nil {\n\tvar root error = err\n\tfor errors.Unwrap(root) != nil { root = errors.Unwrap(root) }\n\treturn fmt.Errorf(\"collector creation failed (%v): %w\", root, err)\n}","preventionTips":["Use unique collector names per run.","Create collectors before workload execution, not during shutdown.","Reinstall matched BAML binaries if construction fails consistently."],"tags":["go","ffi","collector","constructor"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}