{"record":{"id":"c4660fbf4b75ccc8","repo":"BoundaryML/baml","slug":"encoding-client-registry-w","errorCode":null,"errorMessage":"encoding client registry: %w","messagePattern":"encoding client registry: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_args.go","lineNumber":39,"sourceCode":"func (args *BamlFunctionArguments) Encode() ([]byte, error) {\n\tencoded, err := args.encode()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn proto.Marshal(encoded)\n}\n\nfunc (args *BamlFunctionArguments) encode() (*cffi.HostFunctionArguments, error) {\n\tkwargs, err := serde.EncodeMapEntries(args.Kwargs, \"function arguments\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"encoding function arguments: %w\", err)\n\t}\n\n\tvar clientRegistry *cffi.HostClientRegistry\n\tif args.ClientRegistry != nil {\n\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)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_args.go#L21-L57","documentation":"When BamlFunctionArguments carries a ClientRegistry, encode() converts it to the CFFI HostClientRegistry via encodeClientRegistry. Failure here means the registry's client definitions (name, provider, options) could not be serialized, and the error is wrapped with this prefix.","triggerScenarios":"Passing a ClientRegistry to CallFunction/SetBamlOptions where a client's options contain non-encodable values (e.g. wrong types in options map) or the registry itself was constructed inconsistently.","commonSituations":"Building a runtime client registry whose options map includes non-primitive values; typos in provider options that produce malformed entries; passing a registry from an incompatible runtime version.","solutions":["Inspect each client in the registry: only primitive values (string, int, bool, float) in options maps","Rebuild the ClientRegistry with baml.NewClientRegistry and NewClientBuilder instead of hand-rolling it","Remove or fix the custom registry and fall back to the runtime's default clients from clients.baml","Ensure registry client names match those referenced in the BAML functions"],"exampleFix":"// before\nregistry.Options()[\"retry\"] = myCustomRetryPolicy{} // not encodable\n// after\nregistry.Options()[\"retry\"] = 3 // primitive value only","handlingStrategy":"validation","validationCode":"func validRegistry(r *ClientRegistry) bool {\n    if r == nil { return false }\n    for _, o := range r.Options() {\n        switch o.(type) {\n        case string, int, int64, float64, bool, nil:\n        default: return false\n        }\n    }\n    return true\n}","typeGuard":null,"tryCatchPattern":"res, err := runtime.CallFunction(ctx, \"Fn\", params, kwargs, registry)\nif err != nil && strings.Contains(err.Error(), \"encoding client registry\") {\n    return fmt.Errorf(\"client registry options must be primitives: %w\", err)\n}","preventionTips":["Build registries only via NewClientRegistry/NewClientBuilder","Keep client options to primitive values","Name registry clients exactly as referenced in clients.baml"],"tags":["go","serialization","ffi","client-registry"],"backgroundTag":"invalid-argument-format","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}