From 57fc1d21e18c0c698cd5ca86bcbbbaef352cad50 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 22 Jul 2019 09:51:13 +0200 Subject: [PATCH] cmd/geth, core/rawdb: add missing error checks (#19871) * Added missing error checks Add error handling where we assign err a value, but don't check for it being nil. * core/rawdb: tiny style nit --- cmd/geth/retesteth.go | 3 +++ core/rawdb/freezer_table.go | 4 +++- core/rawdb/freezer_table_test.go | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/geth/retesteth.go b/cmd/geth/retesteth.go index 0615f446f..8453f753f 100644 --- a/cmd/geth/retesteth.go +++ b/cmd/geth/retesteth.go @@ -533,6 +533,9 @@ func (api *RetestethAPI) mineBlock() error { } } block, err := api.engine.FinalizeAndAssemble(api.blockchain, header, statedb, txs, []*types.Header{}, receipts) + if err != nil { + return err + } return api.importBlock(block) } diff --git a/core/rawdb/freezer_table.go b/core/rawdb/freezer_table.go index 2fe354a06..61804f1f2 100644 --- a/core/rawdb/freezer_table.go +++ b/core/rawdb/freezer_table.go @@ -272,7 +272,9 @@ func (t *freezerTable) repair() error { if newLastIndex.filenum != lastIndex.filenum { // Release earlier opened file t.releaseFile(lastIndex.filenum) - t.head, err = t.openFile(newLastIndex.filenum, openFreezerFileForAppend) + if t.head, err = t.openFile(newLastIndex.filenum, openFreezerFileForAppend); err != nil { + return err + } if stat, err = t.head.Stat(); err != nil { // TODO, anything more we can do here? // A data file has gone missing... diff --git a/core/rawdb/freezer_table_test.go b/core/rawdb/freezer_table_test.go index 253c00f5a..4d4375380 100644 --- a/core/rawdb/freezer_table_test.go +++ b/core/rawdb/freezer_table_test.go @@ -113,6 +113,9 @@ func TestFreezerBasicsClosing(t *testing.T) { f.Append(uint64(x), data) f.Close() f, err = newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) + if err != nil { + t.Fatal(err) + } } defer f.Close() @@ -170,6 +173,9 @@ func TestFreezerRepairDanglingHead(t *testing.T) { // Now open it again { f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) + if err != nil { + t.Fatal(err) + } // The last item should be missing if _, err = f.Retrieve(0xff); err == nil { t.Errorf("Expected error for missing index entry") @@ -217,6 +223,9 @@ func TestFreezerRepairDanglingHeadLarge(t *testing.T) { // Now open it again { f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) + if err != nil { + t.Fatal(err) + } // The first item should be there if _, err = f.Retrieve(0); err != nil { t.Fatal(err) @@ -269,6 +278,9 @@ func TestSnappyDetection(t *testing.T) { // Open without snappy { f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, false) + if err != nil { + t.Fatal(err) + } if _, err = f.Retrieve(0); err == nil { f.Close() t.Fatalf("expected empty table") @@ -278,6 +290,9 @@ func TestSnappyDetection(t *testing.T) { // Open with snappy { f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) + if err != nil { + t.Fatal(err) + } // There should be 255 items if _, err = f.Retrieve(0xfe); err != nil { f.Close()