-
Couldn't load subscription status.
- Fork 918
GODRIVER-3361 Improve connection error message. #2027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1cbbbda
076f0df
9cefb59
c3a7110
482f746
64c75e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,10 @@ import ( | |||||
| "context" | ||||||
| "errors" | ||||||
| "fmt" | ||||||
| "io" | ||||||
| "net" | ||||||
| "os" | ||||||
| "strings" | ||||||
| "time" | ||||||
|
|
||||||
| "go.mongodb.org/mongo-driver/v2/x/mongo/driver/description" | ||||||
|
|
@@ -28,21 +32,28 @@ type ConnectionError struct { | |||||
|
|
||||||
| // Error implements the error interface. | ||||||
| func (e ConnectionError) Error() string { | ||||||
| message := e.message | ||||||
| var messages []string | ||||||
| if e.init { | ||||||
| fullMsg := "error occurred during connection handshake" | ||||||
| if message != "" { | ||||||
| fullMsg = fmt.Sprintf("%s: %s", fullMsg, message) | ||||||
| } | ||||||
| message = fullMsg | ||||||
| messages = append(messages, "error occurred during connection handshake") | ||||||
| } | ||||||
| if e.Wrapped != nil && message != "" { | ||||||
| return fmt.Sprintf("connection(%s) %s: %s", e.ConnectionID, message, e.Wrapped.Error()) | ||||||
| if e.message != "" { | ||||||
| messages = append(messages, e.message) | ||||||
| } | ||||||
| if e.Wrapped != nil { | ||||||
| return fmt.Sprintf("connection(%s) %s", e.ConnectionID, e.Wrapped.Error()) | ||||||
| if errors.Is(e.Wrapped, io.EOF) { | ||||||
| messages = append(messages, "socket was unexpectedly closed") | ||||||
|
||||||
| messages = append(messages, "socket was unexpectedly closed") | |
| messages = append(messages, "connection closed unexpectedly by the other side") |
The ticket suggests "Wrap[ping] io.EOF with an additional error message, like 'connection closed unexpectedly by the other side'". The idea being that we let the user know nothing driver-side is responsible. When the driver closes a connection I would expect something like this: use of closed network connection. Here is a gist with both examples: https://gist.github.com/prestonvasquez/bbab8370950e9c98fa422b6b1ae1069a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the transformNetworkError function will wrap the error with context.DeadlineExceeded. Should we include that case here for safety?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding a compile check for
ConnectionError, I just noticed we don't do this: