Skip to content

Commit

Permalink
cmd/geth, core/rawdb: add missing error checks (#19871)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
muesli authored and karalabe committed Jul 22, 2019
1 parent cc3ef1e commit 57fc1d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/geth/retesteth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion core/rawdb/freezer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
15 changes: 15 additions & 0 deletions core/rawdb/freezer_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit 57fc1d2

Please sign in to comment.