{"record":{"id":"eeb08313df0f5e49","repo":"BoundaryML/baml","slug":"nil-collector-found-in-collectors","errorCode":null,"errorMessage":"nil collector found in collectors","messagePattern":"nil collector found in collectors","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_args.go","lineNumber":55,"sourceCode":"\t\tclientRegistry, err = encodeClientRegistry(args.ClientRegistry)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"encoding client registry: %w\", err)\n\t\t}\n\t}\n\n\tvar env []*cffi.HostEnvVar\n\tif args.Env != nil {\n\t\tenv, err = serde.EncodeEnvVar(args.Env)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"encoding env vars: %w\", err)\n\t\t}\n\t}\n\n\tvar collectors []*cffi.BamlObjectHandle\n\tif args.Collectors != nil {\n\t\tfor _, collector := range args.Collectors {\n\t\t\tif collector == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"nil collector found in collectors\")\n\t\t\t}\n\t\t\tencodedCollector := raw_objects.EncodeRawObject(collector)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"encoding collector: %w\", err)\n\t\t\t}\n\t\t\tcollectors = append(collectors, encodedCollector)\n\t\t}\n\t}\n\n\tvar typeBuilder *cffi.BamlObjectHandle\n\tif args.TypeBuilder != nil {\n\t\tencodedTypeBuilder := raw_objects.EncodeRawObject(args.TypeBuilder)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"encoding type builder: %w\", err)\n\t\t}\n\t\ttypeBuilder = encodedTypeBuilder\n\t}\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_args.go#L37-L73","documentation":"When encoding the Collectors list for a function call, each collector must be a valid raw object handle. A nil element in the Collectors slice cannot be encoded as a BamlObjectHandle, so this explicit error is returned before crossing the FFI boundary.","triggerScenarios":"Passing a Collectors slice to BamlFunctionArguments that contains a nil entry — e.g. building the slice with make([]Collector, n) and only partially filling it, or appending a zero-valued collector.","commonSituations":"Preallocating a collectors slice with make(..., 2) but registering only one; a collector variable that failed to initialize earlier (err ignored); copying collectors between calls with a nil placeholder.","solutions":["Filter out nil entries before assigning args.Collectors","Use collectory.NewCollector (the constructor) for each collector rather than zero-value structs","Check that the collector creation call returned no error and a non-nil value","Only pass args.Collectors when len > 0 and all entries are non-nil"],"exampleFix":"// before\ncollectors := make([]Collector, 2)\ncollectors[0] = c\nargs.Collectors = collectors // collectors[1] is nil\n// after\ncollectors := []Collector{c}\nargs.Collectors = collectors","handlingStrategy":"validation","validationCode":"func hasNilCollector(cs []Collector) bool {\n    for _, c := range cs { if c == nil { return true } }\n    return false\n}","typeGuard":null,"tryCatchPattern":"if hasNilCollector(collectors) {\n    return errors.New(\"collectors contains a nil entry\")\n}\n// then proceed with args.Collectors = collectors","preventionTips":["Append collectors with append(nil-slice, c...) instead of preallocating with make(..., n)","Check constructor errors so collector variables are never nil","Only set args.Collectors when all entries are non-nil"],"tags":["go","nil-check","collectors","ffi"],"backgroundTag":"null-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"}