{"record":{"id":"ebc9a8757b801504","repo":"github/copilot-sdk","slug":"failed-to-log-message-w","errorCode":null,"errorMessage":"failed to log message: %w","messagePattern":"failed to log message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/session.go","lineNumber":2087,"sourceCode":"//\tsession.Log(ctx, \"Rate limit approaching\", &copilot.LogOptions{Level: rpc.SessionLogLevelWarning})\n//\n//\t// Ephemeral message (not persisted)\n//\tsession.Log(ctx, \"Working...\", &copilot.LogOptions{Ephemeral: copilot.Bool(true)})\nfunc (s *Session) Log(ctx context.Context, message string, opts *LogOptions) error {\n\tparams := &rpc.LogRequest{Message: message}\n\n\tif opts != nil {\n\t\tif opts.Level != \"\" {\n\t\t\tparams.Level = &opts.Level\n\t\t}\n\t\tif opts.Ephemeral != nil {\n\t\t\tparams.Ephemeral = opts.Ephemeral\n\t\t}\n\t}\n\n\t_, err := s.RPC.Log(ctx, params)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to log message: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":2069,"sourceCodeEnd":2092,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/session.go#L2069-L2092","documentation":"Session's logging path builds a log request from LogOptions (including optional ephemeral flag) and calls s.RPC.Log. This error wraps any failure of that RPC — the runtime rejected the log level/options or the transport failed.","triggerScenarios":"Calling the session Log API (with LogOptions) when the `Log` RPC fails: invalid level/options for the runtime, dead connection, or unknown session.","commonSituations":"Emitting logs after the session/runtime was torn down; using a log option not supported by the running runtime; logging from a goroutine racing session disconnect.","solutions":["Check the wrapped error for the runtime's specific rejection","Verify the session is still connected before logging","Validate LogOptions (level, ephemeral) against the runtime version","Make logging non-fatal: log-and-continue instead of propagating"],"exampleFix":"// before\nif err := session.Log(ctx, LevelInfo, msg, opts); err != nil { return err }\n// after\nif err := session.Log(ctx, LevelInfo, msg, opts); err != nil {\n    log.Printf(\"session log dropped: %v\", err) // keep app running\n}","handlingStrategy":"try-catch","validationCode":"if session == nil || session.SessionID == \"\" {\n    return errors.New(\"cannot log: session not connected\")\n}","typeGuard":null,"tryCatchPattern":"if err := session.Log(ctx, level, msg, opts); err != nil {\n    log.Printf(\"session log failed (dropped): %v\", err)\n    // do not propagate; logging must not break the app\n}","preventionTips":["Never let session-logging errors crash the application","Verify LogOptions (level, ephemeral) match the runtime's capabilities","Avoid logging from goroutines that outlive Disconnect"],"tags":["go","logging","rpc","session"],"backgroundTag":"api-request-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}