{"record":{"id":"653134d4aa62e4d7","repo":"BoundaryML/baml","slug":"failed-to-get-logs-w","errorCode":null,"errorMessage":"failed to get logs: %w","messagePattern":"failed to get logs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_collector.go","lineNumber":58,"sourceCode":"\nfunc (c *collector) Name() (string, error) {\n\tresult, err := raw_objects.CallMethod(c, \"name\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get name: %w\", err)\n\t}\n\n\tname, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for name: %T\", result)\n\t}\n\n\treturn name, nil\n}\n\nfunc (c *collector) Logs() ([]FunctionLog, error) {\n\tresult, err := raw_objects.CallMethod(c, \"logs\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get logs: %w\", err)\n\t}\n\n\tlogs, ok := result.([]raw_objects.RawPointer)\n\tif !ok {\n\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}","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_collector.go#L40-L76","documentation":"Collector.Logs() calls the runtime's `logs` method and wraps any CallMethod failure as \"failed to get logs: %w\". The real cause is in the wrapped error: an FFI failure, a runtime exception inside `logs`, or an invalid collector object. It means the log list could not be retrieved at all — the subsequent type assertion on the result never ran.","triggerScenarios":"Calling collector.Logs() when the runtime object is invalid/freed, the runtime raises while collecting logs, or the FFI bridge fails before returning a slice.","commonSituations":"Reading logs after the BAML runtime shut down; using a collector from a different process/runtime instance; races where one goroutine calls Clear() while another calls Logs().","solutions":["Unwrap the error (errors.Unwrap) to see the underlying failure before changing application code.","Keep collector usage within the lifetime of the BAML runtime; recreate the collector after any runtime restart.","Synchronize concurrent access to the collector (Clear vs Logs) with a mutex.","Retry once to rule out transient FFI failures, then check runtime logs."],"exampleFix":"// before\nlogs, err := collector.Logs()\n// after\nlogs, err := collector.Logs()\nif err != nil {\n    return nil, fmt.Errorf(\"logs unavailable: %w (cause: %v)\", err, errors.Unwrap(err))\n}","handlingStrategy":"try-catch","validationCode":"// Guard against races: serialize Clear()/Logs() access with a mutex in your code","typeGuard":"func hasLogs(c baml.Collector) bool { return c != nil }","tryCatchPattern":"logs, err := collector.Logs()\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to get logs\") {\n        time.Sleep(50 * time.Millisecond)\n        logs, err = collector.Logs() // one retry for transient FFI issues\n    }\n    if err != nil {\n        return nil, fmt.Errorf(\"logs unavailable: %w\", err)\n    }\n}","preventionTips":["Synchronize Clear() and Logs() calls across goroutines","Only read logs within the BAML runtime's lifetime","Inspect errors.Unwrap(err) for the true cause","Recreate the collector after runtime restarts"],"tags":["go","ffi","collector","logging"],"backgroundTag":"api-request-failed","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"}