{"record":{"id":"bd199e7a533973d1","repo":"BoundaryML/baml","slug":"unexpected-type-for-collector-creation-t","errorCode":null,"errorMessage":"unexpected type for collector creation: %T","messagePattern":"unexpected type for collector creation: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_constructors.go","lineNumber":27,"sourceCode":")\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}\n\n\tptr, err := raw_objects.NewRawObject(r.runtime, mediaType.objectType(), kwargs)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create media: %w\", err)\n\t}","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_constructors.go#L9-L45","documentation":"NewCollector calls the Rust runtime's raw object factory and then asserts the returned generic pointer is a *collector. If the runtime returns any other concrete Go wrapper type, this error is thrown. It is an internal consistency check: it means the cffi layer and the Go wrapper types have drifted out of sync, not that caller input was wrong.","triggerScenarios":"Calling baml.NewCollector() when raw_objects.NewRawObject(OBJECT_TYPE_COLLECTOR) returns a non-*collector value — i.e. a version mismatch between the generated cffi bindings and the hand-written Go wrappers, or a runtime bug in NewRawObject dispatch.","commonSituations":"Mixing a BAML Go SDK version with a mismatched native library/binary (e.g. after a partial upgrade), custom builds of the engine, or an upstream cffi change that renamed or reordered object types.","solutions":["Check that the baml Go module version and the bundled native runtime are from the same release; run `go mod tidy` and upgrade to a consistent version","Rebuild/re-download the native BAML runtime binary so it matches the Go bindings","If reproducible on a clean install, file a bug with the BAML maintainers including the %T value printed in the message"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Go: ensure module consistency before use\nimport (\n    \"runtime/debug\"\n    baml \"github.com/boundaryml/baml/engine/language_client_go\"\n)\nfunc checkBamlVersion() error {\n    bi, ok := debug.ReadBuildInfo()\n    if !ok { return nil }\n    for _, d := range bi.Deps {\n        if strings.HasPrefix(d.Path, \"github.com/boundaryml/baml\") {\n            _ = d.Version // log and compare against native runtime version\n        }\n    }\n    return nil\n}","typeGuard":"func asCollector(v any) (*collector, bool) {\n    c, ok := v.(*collector)\n    return c, ok\n}","tryCatchPattern":"c, err := baml.NewCollector(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for collector creation\") {\n        return nil, fmt.Errorf(\"baml bindings/runtime version mismatch: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Always upgrade the baml Go module and native runtime together in one change","Pin the SDK version in go.mod and avoid partial dependency updates","Run a smoke test that constructs a Collector at startup to fail fast on binding drift"],"tags":["go","baml-runtime","type-assertion","internal"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}