{"record":{"id":"75c67fdb852f2ebd","repo":"BoundaryML/baml","slug":"unexpected-type-for-clear-result-t","errorCode":null,"errorMessage":"unexpected type for clear result: %T","messagePattern":"unexpected type for clear result: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_collector.go","lineNumber":120,"sourceCode":"\t}\n\n\tlog, ok := result.(FunctionLog)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for log by id: %T\", result)\n\t}\n\n\treturn log, nil\n}\n\nfunc (c *collector) Clear() (int64, error) {\n\tresult, err := raw_objects.CallMethod(c, \"clear\", nil)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to clear: %w\", err)\n\t}\n\n\tcount, ok := result.(int64)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"unexpected type for clear result: %T\", result)\n\t}\n\n\treturn count, nil\n}\n","sourceCodeStart":102,"sourceCodeEnd":125,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_collector.go#L102-L125","documentation":"Go type-assertion failure in the collector's Clear method: the bridge returned the clear result, but it is not an int64 (the %T names the actual type). The runtime and Go bindings disagree on the return shape of 'clear' — typically a version mismatch between the baml runtime and the generated Go library.","triggerScenarios":"collector.Clear() where CallMethod returns a non-int64 (e.g. int, uint64 from a differently-built runtime, or nil).","commonSituations":"Mixed Go/native versions where the runtime returns a different numeric width/type; runtime returning nil on clear.","solutions":["Rebuild against the matching BAML runtime so the return type is int64.","Convert defensively in the client if a custom runtime returns another numeric type.","Report upstream with the %T value if versions match."],"exampleFix":"// before\ncount, ok := result.(int64)\n// after\ncount, ok := result.(int64)\nif !ok {\n\tif f, isF := result.(float64); isF { count = int64(f) }\n}","handlingStrategy":"type-guard","validationCode":"if collector == nil { return errors.New(\"collector not initialized\") }","typeGuard":"func toInt64(v any) (int64, bool) {\n\tswitch n := v.(type) {\n\tcase int64: return n, true\n\tcase int: return int64(n), true\n\tcase float64: return int64(n), true\n\t}\n\treturn 0, false\n}","tryCatchPattern":"count, err := collector.Clear()\nif err != nil {\n\tif strings.Contains(err.Error(), \"unexpected type\") { /* numeric type skew between runtimes */ }\n\treturn err\n}","preventionTips":["Build the Go client against the exact native runtime in use.","Do not mix runtime binary versions.","Treat persistent mismatches as upstream bugs."],"tags":["go","ffi","type-mismatch","collector"],"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"}