{"record":{"id":"fbcdfd2078ccbb0f","repo":"BoundaryML/baml","slug":"unexpected-type-for-calls-count-t","errorCode":null,"errorMessage":"unexpected type for calls count: %T","messagePattern":"unexpected type for calls count: %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_log.go","lineNumber":119,"sourceCode":"\t}\n\n\tresponse, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for raw LLM response: %T\", result)\n\t}\n\n\treturn response, nil\n}\n\nfunc (f *functionLog) CallsCount() (int, error) {\n\tresult, err := raw_objects.CallMethod(f, \"calls_count\", nil)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to get calls count: %w\", err)\n\t}\n\n\tcount, ok := result.(int)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"unexpected type for calls count: %T\", result)\n\t}\n\n\treturn count, nil\n}\n\nfunc (f *functionLog) Calls() ([]LLMCall, error) {\n\tresult, err := raw_objects.CallMethod(f, \"calls\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get calls: %w\", err)\n\t}\n\n\tresult_cast := result.([]raw_objects.RawPointer)\n\tcalls := make([]LLMCall, len(result_cast))\n\n\tfor i, call := range result_cast {\n\t\tcalls[i] = call.(LLMCall)\n\t}\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_log.go#L101-L137","documentation":"CallsCount() type-asserts the bridge result of the 'calls_count' method to Go int; when the runtime returns any other type (e.g. int64, float64, or nil) the assertion fails and this error is thrown. It protects callers from silent numeric-type drift across the runtime boundary.","triggerScenarios":"Calling FunctionLog.CallsCount() when the remote 'calls_count' method returns a numeric type other than Go int (int64/float64 from the marshaling layer) or nil.","commonSituations":"JSON/IPC marshaling that decodes numbers as float64 or int64 instead of int; runtime languages with unbounded integers returning bigint-like values; count unset so nil is returned.","solutions":["Check %T in the error to see the actual numeric type returned","Convert the bridge's number type (e.g. int64 or float64) explicitly before or after the assertion","Align the bridge marshaling config so numbers decode as int"],"exampleFix":"// before\ncount, ok := result.(int)\nif !ok {\n    return 0, fmt.Errorf(\"unexpected type for calls count: %T\", result)\n}\n// after\nvar count int\nswitch v := result.(type) {\ncase int:\n    count = v\ncase int64:\n    count = int(v)\ncase float64:\n    count = int(v)\ndefault:\n    return 0, fmt.Errorf(\"unexpected type for calls count: %T\", result)\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func asInt(v any) (int, bool) {\n    switch n := v.(type) {\n    case int:\n        return n, true\n    case int64:\n        return int(n), true\n    case float64:\n        return int(n), true\n    }\n    return 0, false\n}","tryCatchPattern":"count, err := flog.CallsCount()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for calls count\") {\n        return 0, fmt.Errorf(\"runtime returned non-int count: %w\", err)\n    }\n    return 0, err\n}","preventionTips":["Align bridge marshaling so integers decode as int","Tolerate int64/float64 numerics from runtimes with unbounded ints","Pin runtime and binding versions together"],"tags":["go","type-assertion","numeric","rpc"],"backgroundTag":"type-mismatch","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"}