Skip to content

Commit

Permalink
chore(linter): fix some of the warnings from gas linter
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Feb 13, 2023
1 parent 9800210 commit 6f4b264
Show file tree
Hide file tree
Showing 43 changed files with 337 additions and 82 deletions.
8 changes: 7 additions & 1 deletion codec/benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
"sort"
"time"

"github.com/golang/glog"

"github.com/dgraph-io/dgraph/codec"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/x"
Expand Down Expand Up @@ -62,7 +64,11 @@ func read(filename string) []int {
if err != nil {
x.Panic(err)
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
glog.Warningf("error while closing fd: %v", err)
}
}()

fgzip, err := gzip.NewReader(f)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions conn/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,18 @@ func (p *Pool) MonitorHealth() {
cancel()
if err == nil {
p.Lock()
p.conn.Close()
if err := p.conn.Close(); err != nil {
glog.Warningf("error while closing connection: %v", err)
}
p.conn = conn
p.Unlock()
return
}
glog.Errorf("CONN: Unable to connect with %s : %s\n", p.Addr, err)
if conn != nil {
conn.Close()
if err := conn.Close(); err != nil {
glog.Warningf("error while closing connection: %v", err)
}
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions dgraph/cmd/bulk/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sync"
"time"

"github.com/golang/glog"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -196,7 +197,11 @@ func (ld *loader) leaseNamespaces() {
func readSchema(opt *options) *schema.ParsedSchema {
f, err := filestore.Open(opt.SchemaFile)
x.Check(err)
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
glog.Warningf("error while closing fd: %v", err)
}
}()

key := opt.EncryptionKey
if !opt.Encrypted {
Expand Down Expand Up @@ -334,7 +339,11 @@ func (ld *loader) processGqlSchema(loadType chunker.InputFormat) {

f, err := filestore.Open(ld.opt.GqlSchemaFile)
x.Check(err)
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
glog.Warningf("error while closing fd: %v", err)
}
}()

key := ld.opt.EncryptionKey
if !ld.opt.Encrypted {
Expand Down
7 changes: 6 additions & 1 deletion dgraph/cmd/cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os"
"time"

"github.com/golang/glog"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -128,7 +129,11 @@ func (c *certConfig) generatePair(keyFile, certFile string) error {
}
return err
}
defer fp.Close()
defer func() {
if err := fp.Close(); err != nil {
glog.Warningf("error closing file: %v", err)
}
}()

err = pem.Encode(fp, &pem.Block{
Type: "CERTIFICATE",
Expand Down
7 changes: 6 additions & 1 deletion dgraph/cmd/cert/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"os"
"path/filepath"

"github.com/golang/glog"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -59,7 +60,11 @@ func makeKey(keyFile string, c *certConfig) (crypto.PrivateKey, error) {
}
return nil, err
}
defer fp.Close()
defer func() {
if err := fp.Close(); err != nil {
glog.Warningf("error closing file: %v", err)
}
}()

var key crypto.PrivateKey
switch c.curve {
Expand Down
13 changes: 11 additions & 2 deletions dgraph/cmd/conv/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path/filepath"
"strings"

"github.com/golang/glog"
geojson "github.com/paulmach/go.geojson"

"github.com/dgraph-io/dgraph/x"
Expand All @@ -38,7 +39,11 @@ func writeToFile(fpath string, ch chan []byte) error {
return err
}

defer f.Close()
defer func() {
if err := f.Close(); err != nil {
glog.Warningf("error while closing fd: %v", err)
}
}()
x.Check(err)
w := bufio.NewWriterSize(f, 1e6)
gw, err := gzip.NewWriterLevel(w, gzip.BestCompression)
Expand Down Expand Up @@ -66,7 +71,11 @@ func convertGeoFile(input string, output string) error {
if err != nil {
return err
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
glog.Warningf("error while closing fd: %v", err)
}
}()

var gz io.Reader
if filepath.Ext(input) == ".gz" {
Expand Down
2 changes: 1 addition & 1 deletion dgraph/cmd/debug/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func printKeys(db *badger.DB) {
return err
}
x.Check(stream.Orchestrate(context.Background()))
w.Flush()
x.Check(w.Flush())
fmt.Println()
fmt.Printf("Found %d keys\n", atomic.LoadUint64(&total))
}
Expand Down
30 changes: 25 additions & 5 deletions dgraph/cmd/debuginfo/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func (w *walker) walkPath(path string, info os.FileInfo, err error) error {
glog.Errorf("Failed to open %s: %s", path, err)
return nil
}
defer file.Close()
defer func() {
if err := file.Close(); err != nil {
glog.Warningf("error closing file: %v", err)
}
}()

if info.IsDir() {
if info.Name() == w.baseDir {
Expand Down Expand Up @@ -96,10 +100,18 @@ func createArchive(debugDir string) (string, error) {
if err != nil {
return "", err
}
defer file.Close()
defer func() {
if err := file.Close(); err != nil {
glog.Warningf("error closing file: %v", err)
}
}()

writer := tar.NewWriter(file)
defer writer.Close()
defer func() {
if err := writer.Close(); err != nil {
glog.Warningf("error closing writer: %v", err)
}
}()

var baseDir string
if info, err := os.Stat(debugDir); os.IsNotExist(err) {
Expand Down Expand Up @@ -134,11 +146,19 @@ func createGzipArchive(debugDir string) (string, error) {
if err != nil {
return "", err
}
defer writer.Close()
defer func() {
if err := writer.Close(); err != nil {
glog.Warningf("error closing writer: %v", err)
}
}()

archiver := gzip.NewWriter(writer)
archiver.Name = filename
defer archiver.Close()
defer func() {
if err := archiver.Close(); err != nil {
glog.Warningf("error closing archiver: %v", err)
}
}()

_, err = io.Copy(archiver, reader)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions dgraph/cmd/debuginfo/debugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ func saveDebug(sourceURL, filePath string, duration time.Duration) error {
if err != nil {
return err
}
defer func() {
if err := resp.Close(); err != nil {
glog.Warningf("error closing resp reader: %v", err)
}
}()

defer resp.Close()
out, err := os.Create(filePath)
if err != nil {
return fmt.Errorf("error while creating debug file: %s", err)
Expand All @@ -94,7 +98,11 @@ func fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) {
return nil, fmt.Errorf("http fetch: %v", err)
}
if resp.StatusCode != http.StatusOK {
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
glog.Warningf("error closing body: %v", err)
}
}()
return nil, statusCodeError(resp)
}

Expand Down
6 changes: 5 additions & 1 deletion dgraph/cmd/decrypt/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ func run() {
if err != nil {
glog.Fatalf("Error opening file: %v\n", err)
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
glog.Warningf("error while closing fd: %v", err)
}
}()
reader, err := enc.GetReader(opts.keyfile, f)
x.Checkf(err, "could not open key reader")
if strings.HasSuffix(strings.ToLower(opts.file), ".gz") {
Expand Down
6 changes: 5 additions & 1 deletion dgraph/cmd/live/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ func (l *loader) processSchemaFile(ctx context.Context, file string, key x.Sensi

f, err := filestore.Open(file)
x.CheckfNoTrace(err)
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
glog.Warningf("error while closing fd: %v", err)
}
}()

reader, err := enc.GetReader(key, f)
x.Check(err)
Expand Down
4 changes: 3 additions & 1 deletion dgraph/cmd/zero/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func (o *Oracle) Init() {

// close releases the memory associated with btree used for keycommit.
func (o *Oracle) close() {
o.keyCommit.Close()
if err := o.keyCommit.Close(); err != nil {
glog.Warningf("error while closing tree: %v", err)
}
}

func (o *Oracle) updateStartTxnTs(ts uint64) {
Expand Down
13 changes: 10 additions & 3 deletions ee/audit/run_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,20 @@ func run() error {

file, err := os.Open(decryptCmd.Conf.GetString("in"))
x.Check(err)
defer file.Close()
defer func() {
if err := file.Close(); err != nil {
glog.Warningf("error closing file: %v", err)
}
}()

outfile, err := os.OpenFile(decryptCmd.Conf.GetString("out"),
os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
x.Check(err)
defer outfile.Close()

defer func() {
if err := outfile.Close(); err != nil {
glog.Warningf("error closing file: %v", err)
}
}()
block, err := aes.NewCipher(key)
x.Check(err)

Expand Down
2 changes: 1 addition & 1 deletion ee/backup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func runLsbackupCmd() error {
if err != nil {
fmt.Println("error:", err)
}
os.Stdout.Write(b)
_, _ = os.Stdout.Write(b)
fmt.Println()
return nil
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/philhofer/fwd v1.0.0 // indirect
github.com/pierrec/lz4 v2.6.0+incompatible // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
github.com/dgraph-io/badger/v3 v3.2103.6-0.20230206174300-f35dd0f0c98c h1:r/szX2ayiqpRXyvfwUDBKAAtkDAY9pgMka8fLb5i1gw=
github.com/dgraph-io/badger/v3 v3.2103.6-0.20230206174300-f35dd0f0c98c/go.mod h1:4MPiseMeDQ3FNCYwRbbcBOGJLf5jsE0PPFzRiKjtcdw=
github.com/dgraph-io/badger/v3 v3.2103.6-0.20230209075919-3045f88d615c h1:CxDBAdDBThd0cOT9xboEzbKQ0s5b3RxQnXSL0/O8BqQ=
github.com/dgraph-io/badger/v3 v3.2103.6-0.20230209075919-3045f88d615c/go.mod h1:4MPiseMeDQ3FNCYwRbbcBOGJLf5jsE0PPFzRiKjtcdw=
github.com/dgraph-io/dgo/v210 v210.0.0-20210407152819-261d1c2a6987 h1:5aN6H88a2q3HkO8vSZxDlgjEpJf4Fz8rfy+/Wzx2uAc=
Expand Down Expand Up @@ -527,7 +525,6 @@ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59P
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/basictracer-go v1.1.0/go.mod h1:V2HZueSJEp879yv285Aap1BS69fQMD+MNP1mRs6mBQc=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/ory/dockertest v3.3.4+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
Expand Down
7 changes: 6 additions & 1 deletion graphql/authorization/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/dgrijalva/jwt-go/v4"
"github.com/golang/glog"
"github.com/pkg/errors"
"google.golang.org/grpc/metadata"
"gopkg.in/square/go-jose.v2"
Expand Down Expand Up @@ -461,7 +462,11 @@ func (a *AuthMeta) FetchJWK(i int) error {
if err != nil {
return err
}
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
glog.Warningf("error closing body: %v", err)
}
}()

data, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions graphql/e2e/common/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"testing"

"github.com/gogo/protobuf/jsonpb"
"github.com/golang/glog"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pkg/errors"
Expand Down Expand Up @@ -303,7 +304,11 @@ func health(t *testing.T) {
var health []pb.HealthInfo
resp, err := http.Get(dgraphHealthURL)
require.NoError(t, err)
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
glog.Warningf("error closing body: %v", err)
}
}()
healthRes, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, json.Unmarshal(healthRes, &health))
Expand Down Expand Up @@ -474,7 +479,11 @@ func adminState(t *testing.T) {
var state pb.MembershipState
resp, err := http.Get(dgraphStateURL)
require.NoError(t, err)
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
glog.Warningf("error closing body: %v", err)
}
}()
stateRes, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, jsonpb.Unmarshal(bytes.NewReader(stateRes), &state))
Expand Down
Loading

0 comments on commit 6f4b264

Please sign in to comment.