{"record":{"id":"b7b08635bf2c65df","repo":"BoundaryML/baml","slug":"unexpected-type-for-function-name-t","errorCode":null,"errorMessage":"unexpected type for function name: %T","messagePattern":"unexpected type for function name: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_log.go","lineNumber":49,"sourceCode":"\t}\n\n\tid, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for ID: %T\", result)\n\t}\n\n\treturn id, nil\n}\n\nfunc (f *functionLog) FunctionName() (string, error) {\n\tresult, err := raw_objects.CallMethod(f, \"function_name\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get function name: %w\", err)\n\t}\n\n\tname, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for function name: %T\", result)\n\t}\n\n\treturn name, nil\n}\n\nfunc (f *functionLog) LogType() (string, error) {\n\tresult, err := raw_objects.CallMethod(f, \"log_type\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get log type: %w\", err)\n\t}\n\n\tlogType, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for log type: %T\", result)\n\t}\n\n\treturn logType, nil\n}","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_log.go#L31-L67","documentation":"Returned by FunctionName() when the runtime successfully answered the 'function_name' method call, but the decoded Go value is not a string (the `result.(string)` assertion failed). The library guards its FFI contract with this assertion, so hitting it means the runtime returned a differently-typed representation than the Go client expects — usually a version/contract mismatch or object corruption, never a normal user-visible value problem.","triggerScenarios":"function_name on the Rust side decodes into a non-string Go object (e.g. class instance or map) instead of string; mismatched client/runtime versions where the field representation changed.","commonSituations":"Upgrading the BAML CLI without regenerating the Go client (or vice versa); corrupted/stale functionLog objects reused after stream completion; a bug in decodeObjectResponse producing an unexpected variant.","solutions":["Regenerate/re-version the Go client (`baml generate`) so it matches the installed BAML runtime version.","Capture the %T value in the error message — it reveals what type the runtime actually returned and helps diagnose the mismatch.","Avoid holding functionLog references after the owning function stream finished; recreate access from the current response.","If reproducible on a fresh, valid log object, file a bug with BAML including the printed Go type."],"exampleFix":"// before\nname, err := fnLog.FunctionName()\n// after\nname, err := fnLog.FunctionName()\nif err != nil {\n    var typeErr *fmt.Errorf\n    _ = typeErr // inspect message for \"unexpected type for function name: %T\" and log the dynamic type\n    return \"\", err\n}","handlingStrategy":"type-guard","validationCode":"if fnLog == nil {\n    return errors.New(\"function log is nil; cannot read FunctionName\")\n}","typeGuard":"func nameIsString(v any) (string, bool) {\n    s, ok := v.(string)\n    return s, ok\n}","tryCatchPattern":"name, err := fnLog.FunctionName()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for function name:\") {\n        // capture the dynamic type printed after the colon for diagnosis\n        return \"\", fmt.Errorf(\"client/runtime contract mismatch: %w\", err)\n    }\n    return \"\", err\n}","preventionTips":["Regenerate the Go client whenever the BAML engine/CLI is upgraded.","Extract and report the %T type in the message when filing bugs.","Avoid using functionLog objects after their stream has been consumed.","Pin client and runtime versions together in your dependency lockfile."],"tags":["go","ffi","type-mismatch","baml"],"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"}