{"record":{"id":"ad0cc36cccbeb415","repo":"BoundaryML/baml","slug":"failed-to-get-last-log-w","errorCode":null,"errorMessage":"failed to get last log: %w","messagePattern":"failed to get last log: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_collector.go","lineNumber":81,"sourceCode":"\t\treturn nil, fmt.Errorf(\"unexpected type for logs: %T\", result)\n\t}\n\n\tfunctionLogs := make([]FunctionLog, len(logs))\n\tfor i, log := range logs {\n\t\tcast, ok := log.(FunctionLog)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"unexpected type in logs: %T\", log)\n\t\t}\n\t\tfunctionLogs[i] = cast\n\t}\n\n\treturn functionLogs, nil\n}\n\nfunc (c *collector) Last() (FunctionLog, error) {\n\tresult, err := raw_objects.CallMethod(c, \"last\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get last log: %w\", err)\n\t}\n\n\tif result == nil {\n\t\treturn nil, nil\n\t}\n\n\tlog, ok := result.(FunctionLog)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for last log: %T %v\", result, result)\n\t}\n\n\treturn log, nil\n}\n\nfunc (c *collector) Id(functionId string) (FunctionLog, error) {\n\tresult, err := raw_objects.CallMethod(c, \"id\", map[string]any{\n\t\t\"id\": functionId,\n\t})","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_collector.go#L63-L99","documentation":"Wraps any error returned by CallMethod(c, \"last\") in Collector.Last() (rawobjects_collector.go:81). The underlying FFI call to the native collector's 'last' method failed — e.g. the raw object handle is invalid or the runtime reported an error.","triggerScenarios":"Calling collector.Last() when the native runtime call fails: invalid/stale collector pointer, runtime panic surfaced through FFI, or runtime-side 'last' error (e.g. no logs in a misconfigured collector).","commonSituations":"Using a Collector after the BAML runtime was torn down; FFI marshalling failures; runtime errors from calling last() on an empty collector in some runtime versions.","solutions":["Check err chain (errors.Unwrap) for the root FFI/runtime cause.","Verify the collector was created by the same live runtime instance.","Handle nil result: Last() returns (nil, nil) for an empty collector — check before use.","Upgrade/reinstall matching BAML client + native binaries."],"exampleFix":"// before\nlog, _ := collector.Last()\nfmt.Println(log)\n// after\nlog, err := collector.Last()\nif err != nil {\n\treturn err\n}\nif log == nil {\n\treturn nil // collector is empty\n}","handlingStrategy":"try-catch","validationCode":"if collector == nil { return errors.New(\"collector not initialized\") }","typeGuard":"func lastLogOrNil(c baml.Collector) baml.FunctionLog {\n\tl, err := c.Last()\n\tif err != nil || l == nil { return nil }\n\treturn l\n}","tryCatchPattern":"log, err := collector.Last()\nif err != nil {\n\treturn fmt.Errorf(\"collector.Last failed: %w\", err)\n}\nif log == nil { /* empty collector: no logs yet */ }","preventionTips":["Check for nil return — Last() signals an empty collector with (nil, nil).","Keep the owning runtime alive while using the collector.","Unwrap the error chain to find the FFI root cause."],"tags":["go","ffi","collector"],"backgroundTag":"unexpected-api-response-shape","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"}