[GODRIVER-1227] Goland throw warnings from client.Ping method Created: 10/Aug/19  Updated: 27/Oct/23  Resolved: 12/Aug/19

Status: Closed
Project: Go Driver
Component/s: Connections
Affects Version/s: 1.0.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ivan Skiridomov Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

go 1.12.x
github.com/gin-gonic/gin v1.4.0
github.com/golang/snappy v0.0.1 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spf13/viper v1.4.0
github.com/tidwall/pretty v1.0.0 // indirect
github.com/toorop/gin-logrus v0.0.0-20190701131413-6c374ad36b67
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.0.4
gopkg.in/src-d/go-git.v4 v4.13.1


Attachments: PNG File Screenshot 2019-08-10 at 9.07.11 PM.png    

 Description   

I'm using JetBrains Goland IDE with next simple code to connection ping

// code placeholder
ctx, cancel := context.WithTimeout(context.Background(), appConfig.DB.Timeout*time.Second)
client, err := mongo.Connect(ctx, options.Client().ApplyURI(appConfig.DB.URI))
defer cancel()
//Call the connect function of client
//noinspection GoNilness
err = client.Ping(ctx, readpref.Primary())
if err != nil {
   logrus.WithField("mongo", appConfig.DB.URI).Fatal("Mongo connection failed after timeout")
} else {
   logrus.WithField("mongo", appConfig.DB.URI).Info("Mongo connected")
   appConfig.DB.Client = client
}

method err = client.Ping(ctx, readpref.Primary()) show an error with message:

Can I fix myself in my code or it's deeper?

 



 Comments   
Comment by Ivan Skiridomov [ 10/Aug/19 ]

My bad, I have found a bug. I have not to handle previous err statement. So after it, error was gone.

// code placeholder
ctx, cancel := context.WithTimeout(context.Background(), appConfig.DB.Timeout*time.Second)
client, err := mongo.Connect(ctx, options.Client().ApplyURI(appConfig.DB.URI))
// Added <-----
helpers.CheckIfError(err)
//
defer cancel()
//Call the connect function of client
 
 
err = client.Ping(ctx, readpref.Primary())

Comment by Ivan Skiridomov [ 10/Aug/19 ]

WA: I have added

//GoNilness

above this line to suppress the message

Generated at Thu Feb 08 08:35:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.