In the Go Driver, there are various places where we compare context.Canceled to an error using equality (==). It would be more robust to use errors.Is, in case the error we are comparing to is wrapped. Here is a Go Playground example to demonstrate this behavior:
package main import ( "context" "errors" "fmt" ) func main() { // Wrap a context.Canceled error: err := fmt.Errorf("%w", context.Canceled) fmt.Println("using errors package: ", errors.Is(err, context.Canceled)) fmt.Println("using direct comparison: ", err == context.Canceled) }
Here is a non-exhaustive list of places where direct comparisons occur:
x/mongo/driver/topology/connection.go#L317
x/mongo/driver/topology/connection.go#L871
- is related to
-
GODRIVER-2156 Enable all remaining golangci-lint linters and fix any identified issues
- Closed
- is scoped by
-
GODRIVER-2603 Use errors API from Go 1.13
- Closed