{"record":{"id":"27484db61dc0a5c1","repo":"BoundaryML/baml","slug":"unexpected-type-for-id-t","errorCode":null,"errorMessage":"unexpected type for ID: %T","messagePattern":"unexpected type for ID: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_log.go","lineNumber":35,"sourceCode":"}\n\nfunc (f *functionLog) ObjectType() cffi.BamlObjectType {\n\treturn cffi.BamlObjectType_OBJECT_FUNCTION_LOG\n}\n\nfunc (f *functionLog) pointer() int64 {\n\treturn f.RawObject.Pointer()\n}\n\nfunc (f *functionLog) Id() (string, error) {\n\tresult, err := raw_objects.CallMethod(f, \"id\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get ID: %w\", err)\n\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}","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_log.go#L17-L53","documentation":"This error is returned by the Id() accessor on a BAML FunctionLog object. The library fetched the 'id' attribute of the underlying function-log object via its Rust runtime over the C FFI (raw_objects.CallMethod), and the returned value was not a Go string. This indicates the runtime returned a value whose Go representation does not match the expected type, typically meaning the runtime object is corrupt, the pointer is stale (object already destroyed), or an internal decoder bug.","triggerScenarios":"Calling Id() on a functionLog whose underlying BAML runtime object has been released or whose 'id' attribute decodes to a non-string cffi value (e.g. a class/map/object instead of a string).","commonSituations":"Holding a FunctionLog reference after the function stream completed and the runtime freed the object; running a mismatched baml Go client against an older/newer BAML runtime that changed the id field's representation; internal decodeObjectResponse returning an unexpected variant.","solutions":["Do not use the FunctionLog after its owning function call/stream has finished and been consumed; obtain the log and read Id() within the same iteration/callback.","Print the wrapped inner error (fmt.Errorf %w chain) to see the underlying CallMethod failure ('failed to call object method function', 'failed to decode object response', etc.).","Verify the Go client version (engine/language_client_go) matches the BAML runtime/CLI version generating the logs; regenerate the client with `baml init`/`baml generate`.","If reproducible with a valid, live object, file a bug with the %T value printed by the error (it names the actual Go type returned)."],"exampleFix":"// before\nid, err := fnLog.Id()\nif err != nil {\n    return fmt.Errorf(\"getting id: %w\", err)\n}\n// after\nid, err := fnLog.Id()\nif err != nil {\n    return fmt.Errorf(\"getting id (log may already be consumed/freed): %w\", err)\n}","handlingStrategy":"type-guard","validationCode":"if fnLog == nil {\n    return errors.New(\"function log is nil; cannot read Id\")\n}","typeGuard":"func idIsString(v any) (string, bool) {\n    s, ok := v.(string)\n    return s, ok\n}","tryCatchPattern":"id, err := fnLog.Id()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for ID\") {\n        // runtime returned a non-string; treat the log object as invalid\n        return fmt.Errorf(\"function log id unavailable (stale object?): %w\", err)\n    }\n    return err\n}","preventionTips":["Consume FunctionLog fields within the same iteration/callback as the function result; never cache log objects past stream completion.","Keep the generated Go client and BAML runtime versions aligned by re-running `baml generate` after engine upgrades.","Log the %T value from the error when it occurs — it identifies the contract mismatch.","Treat any accessor error on a functionLog as a signal the object is stale and re-fetch from the live response."],"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"}