{"record":{"id":"b6304f267b3d66c9","repo":"BoundaryML/baml","slug":"failed-to-get-id-w","errorCode":null,"errorMessage":"failed to get ID: %w","messagePattern":"failed to get ID: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_log.go","lineNumber":30,"sourceCode":"\t*raw_objects.RawObject\n}\n\nfunc newFunctionLog(ptr int64, rt unsafe.Pointer) FunctionLog {\n\treturn &functionLog{raw_objects.FromPointer(ptr, rt)}\n}\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 {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_log.go#L12-L48","documentation":"functionLog.Id() invokes the runtime's 'id' method on the underlying FunctionLog raw object and wraps any FFI failure with this message. It means the host-side call to retrieve the log's unique ID failed (as opposed to the ID having an unexpected Go type, which yields a separate error).","triggerScenarios":"Calling Id() on a FunctionLog obtained from a callback/stream event or GetFunctionLog after the underlying raw object became invalid — e.g. the log handle was already consumed or the runtime was shut down.","commonSituations":"Storing FunctionLog objects and reading Id() after the runtime was closed; accessing Id() inside on_event callbacks on a freed handle; mixed binding/runtime versions corrupting method dispatch.","solutions":["Read Id() promptly, within the same lifecycle as the FunctionLog event/callback","Verify the runtime hasn't been shut down (Finish/Close) before calling Id()","Re-obtain the FunctionLog via runtime.GetFunctionLog(id or name) if the original handle is stale","Check callback code paths keep a Go reference to the log object until Id() is read"],"exampleFix":"// before\nonEvent := func(fl FunctionLog, ev BamlError) {\n    go func() { time.Sleep(1 * time.Hour); id, _ := fl.Id() }() // handle may be gone\n}\n// after\nonEvent := func(fl FunctionLog, ev BamlError) {\n    id, err := fl.Id() // read synchronously while handle is valid\n    if err != nil { log.Printf(\"function log id: %v\", err) }\n}","handlingStrategy":"try-catch","validationCode":"// guard: only call Id() while the runtime is alive and the log is fresh\nselect {\ncase <-runtimeDone:\n    return errors.New(\"runtime already shut down\")\ndefault:\n}","typeGuard":null,"tryCatchPattern":"id, err := fnLog.Id()\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to get ID\") {\n        // handle stale: re-fetch log via runtime.GetFunctionLog or skip\n    }\n    return err\n}","preventionTips":["Read Id() synchronously inside callbacks, never in long-lived goroutines","Keep a Go reference to the FunctionLog until metadata is extracted","Don't call Id() after runtime Finish/Close","Wrap stream/log handling so errors don't silently drop the log object"],"tags":["go","ffi","function-log","lifecycle"],"backgroundTag":"invalid-argument-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}