Skip to content

Commit

Permalink
Fix errcheck warnings. (dgraph-io#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmr authored Jun 10, 2019
1 parent 3f5a4cb commit 05242c4
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 14 deletions.
6 changes: 4 additions & 2 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ func (l *Loader) send() error {
if err := l.throttle.Do(); err != nil {
return err
}
l.db.batchSetAsync(l.entries, func(err error) {
if err := l.db.batchSetAsync(l.entries, func(err error) {
l.throttle.Done(err)
})
}); err != nil {
return err
}

l.entries = make([]*Entry, 0, 1000)
return nil
Expand Down
2 changes: 1 addition & 1 deletion badger/cmd/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func runTest(cmd *cobra.Command, args []string) error {

y.Check(loader.Finish())
}
db.Subscribe(ctx, updater, accountIDS[0], accountIDS[1:]...)
_ = db.Subscribe(ctx, updater, accountIDS[0], accountIDS[1:]...)
}()
}

Expand Down
10 changes: 7 additions & 3 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ func Open(opt Options) (db *DB, err error) {
db.lc.startCompact(db.closers.compactors)

db.closers.memtable = y.NewCloser(1)
go db.flushMemtable(db.closers.memtable) // Need levels controller to be up.
go func() {
_ = db.flushMemtable(db.closers.memtable) // Need levels controller to be up.
}()
}

headKey := y.KeyWithTs(head, math.MaxUint64)
Expand Down Expand Up @@ -913,7 +915,7 @@ func (db *DB) handleFlushTask(ft flushTask) error {
}
// We own a ref on tbl.
err = db.lc.addLevel0Table(tbl) // This will incrRef (if we don't error, sure)
tbl.DecrRef() // Releases our ref.
_ = tbl.DecrRef() // Releases our ref.
return err
}

Expand Down Expand Up @@ -1231,7 +1233,9 @@ func (db *DB) startCompactions() {
if db.closers.memtable != nil {
db.flushChan = make(chan flushTask, db.opt.NumMemtables)
db.closers.memtable = y.NewCloser(1)
go db.flushMemtable(db.closers.memtable)
go func() {
_ = db.flushMemtable(db.closers.memtable)
}()
}
}

Expand Down
4 changes: 3 additions & 1 deletion integration/testgc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func main() {
}
defer db.Close()

go http.ListenAndServe("localhost:8080", nil)
go func() {
_ = http.ListenAndServe("localhost:8080", nil)
}()

closer := y.NewCloser(11)
go func() {
Expand Down
2 changes: 1 addition & 1 deletion levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func (s *levelsController) compactBuildTables(
// -- we're the only holders of a ref).
for j := 0; j < numBuilds; j++ {
if newTables[j] != nil {
newTables[j].DecrRef()
_ = newTables[j].DecrRef()
}
}
errorReturn := errors.Wrapf(firstErr, "While running compaction for: %+v", cd)
Expand Down
12 changes: 9 additions & 3 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ func encodeEntry(e *Entry, buf *bytes.Buffer) (int, error) {
hash := crc32.New(y.CastagnoliCrcTable)

buf.Write(headerEnc[:])
hash.Write(headerEnc[:])
if _, err := hash.Write(headerEnc[:]); err != nil {
return 0, err
}

buf.Write(e.Key)
hash.Write(e.Key)
if _, err := hash.Write(e.Key); err != nil {
return 0, err
}

buf.Write(e.Value)
hash.Write(e.Value)
if _, err := hash.Write(e.Value); err != nil {
return 0, err
}

var crcBuf [crc32.Size]byte
binary.BigEndian.PutUint32(crcBuf[:], hash.Sum32())
Expand Down
8 changes: 6 additions & 2 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func (t *Table) DecrRef() error {

// It's necessary to delete windows files
if t.loadingMode == options.MemoryMap {
y.Munmap(t.mmap)
if err := y.Munmap(t.mmap); err != nil {
return err
}
}
if err := t.fd.Truncate(0); err != nil {
// This is very important to let the FS know that the file is deleted.
Expand Down Expand Up @@ -191,7 +193,9 @@ func OpenTable(fd *os.File, mode options.FileLoadingMode, cksum []byte) (*Table,
// Close closes the open table. (Releases resources back to the OS.)
func (t *Table) Close() error {
if t.loadingMode == options.MemoryMap {
y.Munmap(t.mmap)
if err := y.Munmap(t.mmap); err != nil {
return err
}
}

return t.fd.Close()
Expand Down
4 changes: 3 additions & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ func (vlog *valueLog) rewrite(f *logFile, tr trace.Trace) error {
}

if deleteFileNow {
vlog.deleteLogFile(f)
if err := vlog.deleteLogFile(f); err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit 05242c4

Please sign in to comment.