Skip to content

Commit

Permalink
multi: update database error types.
Browse files Browse the repository at this point in the history
This updates the database error types to leverage
go 1.13 errors.Is/As functionality as well as confirm
to the error infrastructure best practices.
  • Loading branch information
dnldd committed Jul 15, 2020
1 parent 5616620 commit ef83ecd
Show file tree
Hide file tree
Showing 24 changed files with 404 additions and 422 deletions.
46 changes: 15 additions & 31 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,9 @@ func dbFetchSpendJournalEntry(dbTx database.Tx, block *dcrutil.Block) ([]spentTx
// Ensure any deserialization errors are returned as database
// corruption errors.
if isDeserializeErr(err) {
return nil, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("corrupt spend "+
"information for %v: %v", block.Hash(),
err),
}
str := fmt.Sprintf("corrupt spend information for %v: %v",
block.Hash(), err)
return nil, database.MakeError(database.ErrCorruption, str)
}

return nil, err
Expand Down Expand Up @@ -1164,11 +1161,8 @@ func dbFetchUtxoEntry(dbTx database.Tx, hash *chainhash.Hash) (*UtxoEntry, error
// Ensure any deserialization errors are returned as database
// corruption errors.
if isDeserializeErr(err) {
return nil, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("corrupt utxo entry "+
"for %v: %v", hash, err),
}
str := fmt.Sprintf("corrupt utxo entry for %v: %v", hash, err)
return nil, database.MakeError(database.ErrCorruption, str)
}

return nil, err
Expand Down Expand Up @@ -1211,11 +1205,8 @@ func dbFetchUtxoStats(dbTx database.Tx) (*UtxoStats, error) {
// Ensure any deserialization errors are returned as database
// corruption errors.
if isDeserializeErr(err) {
return nil, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("corrupt utxo entry "+
"for %v: %v", hash, err),
}
str := fmt.Sprintf("corrupt utxo entry for %v: %v", hash, err)
return nil, database.MakeError(database.ErrCorruption, str)
}

return nil, err
Expand Down Expand Up @@ -1312,11 +1303,8 @@ func dbFetchGCSFilter(dbTx database.Tx, blockHash *chainhash.Hash) (*gcs.FilterV

filter, err := gcs.FromBytesV2(blockcf2.B, blockcf2.M, serialized)
if err != nil {
return nil, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("corrupt filter for %v: %v", blockHash,
err),
}
str := fmt.Sprintf("corrupt filter for %v: %v", blockHash, err)
return nil, database.MakeError(database.ErrCorruption, str)
}

return filter, nil
Expand Down Expand Up @@ -1511,11 +1499,9 @@ func deserializeBestChainState(serializedData []byte) (bestChainState, error) {
// and work sum length.
expectedMinLen := chainhash.HashSize + 4 + 8 + 8 + 4
if len(serializedData) < expectedMinLen {
return bestChainState{}, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("corrupt best chain state size; min %v "+
"got %v", expectedMinLen, len(serializedData)),
}
str := fmt.Sprintf("corrupt best chain state size; min %v got %v",
expectedMinLen, len(serializedData))
return bestChainState{}, database.MakeError(database.ErrCorruption, str)
}

state := bestChainState{}
Expand All @@ -1536,11 +1522,9 @@ func deserializeBestChainState(serializedData []byte) (bestChainState, error) {
// Ensure the serialized data has enough bytes to deserialize the work
// sum.
if uint32(len(serializedData[offset:])) < workSumBytesLen {
return bestChainState{}, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("corrupt work sum size; want %v "+
"got %v", workSumBytesLen, uint32(len(serializedData[offset:]))),
}
str := fmt.Sprintf("corrupt work sum size; want %v got %v",
workSumBytesLen, uint32(len(serializedData[offset:])))
return bestChainState{}, database.MakeError(database.ErrCorruption, str)
}
workSumBytes := serializedData[offset : offset+workSumBytesLen]
state.workSum = new(big.Int).SetBytes(workSumBytes)
Expand Down
27 changes: 11 additions & 16 deletions blockchain/chainio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,44 +1470,39 @@ func TestBestChainStateDeserializeErrors(t *testing.T) {
tests := []struct {
name string
serialized []byte
errType error
errKind database.ErrorKind
}{
{
name: "nothing serialized",
serialized: hexToBytes(""),
errType: database.Error{ErrorCode: database.ErrCorruption},
errKind: database.ErrCorruption,
},
{
name: "short data in hash",
serialized: hexToBytes("0000"),
errType: database.Error{ErrorCode: database.ErrCorruption},
errKind: database.ErrCorruption,
},
{
name: "short data in work sum",
serialized: hexToBytes("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000001000000000000000500000001000100"),
errType: database.Error{ErrorCode: database.ErrCorruption},
errKind: database.ErrCorruption,
},
}

for _, test := range tests {
// Ensure the expected error type and code is returned.
_, err := deserializeBestChainState(test.serialized)
if !errors.As(err, &test.errType) {
var derr database.Error
if !errors.As(err, &derr) {
t.Errorf("deserializeBestChainState (%s): expected "+
"error type does not match - got %T, want %T",
test.name, err, test.errType)
test.name, err, test.errKind)
continue
}
var derr database.Error
if errors.As(err, &derr) {
var tderr database.Error
if !errors.As(test.errType, &tderr) || derr.ErrorCode != tderr.ErrorCode {
t.Errorf("deserializeBestChainState (%s): "+
"wrong error code got: %v, want: %v",
test.name, derr.ErrorCode,
tderr.ErrorCode)
continue
}
if !errors.Is(derr, test.errKind) {
t.Errorf("deserializeBestChainState (%s): wrong error code "+
"got: %v, want: %v", test.name, derr, test.errKind)
continue
}
}
}
1 change: 1 addition & 0 deletions blockchain/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ replace (
github.com/decred/dcrd/blockchain/stake/v3 => ./stake
github.com/decred/dcrd/blockchain/standalone/v2 => ./standalone
github.com/decred/dcrd/chaincfg/v3 => ../chaincfg
github.com/decred/dcrd/database/v2 => ../database
github.com/decred/dcrd/dcrec/secp256k1/v3 => ../dcrec/secp256k1
github.com/decred/dcrd/dcrutil/v3 => ../dcrutil
github.com/decred/dcrd/txscript/v3 => ../txscript
Expand Down
29 changes: 19 additions & 10 deletions blockchain/go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4=
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE=
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
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/dchest/siphash v1.2.1 h1:4cLinnzVJDKxTCl9B01807Yiy+W7ZzVHj/KIroQRvT4=
Expand All @@ -22,8 +18,6 @@ github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/crypto/ripemd160 v1.0.0 h1:MciTnR4NfBqDFRFjFkrn8WPLP4Vo7t6ww6ghfn6wcXQ=
github.com/decred/dcrd/crypto/ripemd160 v1.0.0/go.mod h1:F0H8cjIuWTRoixr/LM3REB8obcWkmYx0gbxpQWR8RPg=
github.com/decred/dcrd/database/v2 v2.0.1 h1:ghLzkKpVpwvjrdRv3njrEfkvygQpYQX66sGVs8ha+E8=
github.com/decred/dcrd/database/v2 v2.0.1/go.mod h1:ZOaWTv3IlNqCA+y7q3q5EozgmiDOmNwCSq3ntZn2CDo=
github.com/decred/dcrd/dcrec v1.0.0 h1:W+z6Es+Rai3MXYVoPAxYr5U1DGis0Co33scJ6uH2J6o=
github.com/decred/dcrd/dcrec v1.0.0/go.mod h1:HIaqbEJQ+PDzQcORxnqen5/V1FR3B4VpIfmePklt8Q8=
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.0 h1:E5KszxGgpjpmW8vN811G6rBAZg0/S/DftdGqN4FW5x4=
Expand All @@ -42,21 +36,34 @@ github.com/decred/slog v1.0.0 h1:Dl+W8O6/JH6n2xIFN2p3DNjCmjYwvrXsjlSJTQQ4MhE=
github.com/decred/slog v1.0.0/go.mod h1:zR98rEZHSnbZ4WHZtO0iqmSZjDLKhkXfrPTZQKtAonQ=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.1 h1:PZSj/UFNaVp3KxrzHOcS7oyuWA7LoOY/77yCTEFu21U=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d h1:i6RB+Qz1ug7TvJdY4zieRMpnLAtkHSHTOvApNXfLT4A=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34=
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
Expand All @@ -65,3 +72,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
9 changes: 3 additions & 6 deletions blockchain/indexers/addrindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,9 @@ func dbFetchAddrIndexEntries(bucket internalBucket, addrKey [addrKeySize]byte, n
// Ensure any deserialization errors are returned as
// database corruption errors.
if isDeserializeErr(err) {
err = database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("failed to "+
"deserialized address index "+
"for key %x: %v", addrKey, err),
}
str := fmt.Sprintf("failed to deserialized address index "+
"for key %x: %v", addrKey, err)
err = database.MakeError(database.ErrCorruption, str)
}

return nil, 0, err
Expand Down
19 changes: 8 additions & 11 deletions blockchain/indexers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package indexers

import (
"context"
"errors"
"fmt"

"github.com/decred/dcrd/blockchain/v3/internal/progresslog"
Expand Down Expand Up @@ -60,11 +61,9 @@ func dbFetchIndexerTip(dbTx database.Tx, idxKey []byte) (*chainhash.Hash, int32,
indexesBucket := dbTx.Metadata().Bucket(indexTipsBucketName)
serialized := indexesBucket.Get(idxKey)
if len(serialized) < chainhash.HashSize+4 {
return nil, 0, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("unexpected end of data for "+
"index %q tip", string(idxKey)),
}
str := fmt.Sprintf("unexpected end of data for index %q tip",
string(idxKey))
return nil, 0, database.MakeError(database.ErrCorruption, str)
}

var hash chainhash.Hash
Expand Down Expand Up @@ -103,11 +102,9 @@ func dbFetchIndexerVersion(dbTx database.Tx, idxKey []byte) (uint32, error) {
}

if len(serialized) < 4 {
return 0, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("unexpected end of data for "+
"index %q version", string(idxKey)),
}
str := fmt.Sprintf("unexpected end of data for index %q version",
string(idxKey))
return 0, database.MakeError(database.ErrCorruption, str)
}

version := byteOrder.Uint32(serialized)
Expand Down Expand Up @@ -760,7 +757,7 @@ func dropIndexMetadata(db database.DB, idxKey []byte, idxName string) error {
}

err = meta.DeleteBucket(idxKey)
if err != nil && !database.IsError(err, database.ErrBucketNotFound) {
if err != nil && !errors.Is(err, database.ErrBucketNotFound) {
return err
}

Expand Down
15 changes: 5 additions & 10 deletions blockchain/indexers/txindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,16 @@ func dbFetchTxIndexEntry(dbTx database.Tx, txHash *chainhash.Hash) (*TxIndexEntr

// Ensure the serialized data has enough bytes to properly deserialize.
if len(serializedData) < txEntrySize {
return nil, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("corrupt transaction index "+
"entry for %s", txHash),
}
str := fmt.Sprintf("corrupt transaction index entry for %s", txHash)
return nil, database.MakeError(database.ErrCorruption, str)
}

// Load the block hash associated with the block ID.
hash, err := dbFetchBlockHashBySerializedID(dbTx, serializedData[0:4])
if err != nil {
return nil, database.Error{
ErrorCode: database.ErrCorruption,
Description: fmt.Sprintf("corrupt transaction index "+
"entry for %s: %v", txHash, err),
}
str := fmt.Sprintf("corrupt transaction index entry for %s: %v",
txHash, err)
return nil, database.MakeError(database.ErrCorruption, str)
}

// Deserialize the final entry.
Expand Down
7 changes: 2 additions & 5 deletions blockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,7 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
blockHash, err)
}
var dbErr database.Error
if errors.As(err, &dbErr) && dbErr.ErrorCode ==
database.ErrCorruption {
if errors.As(err, &dbErr) && errors.Is(dbErr, database.ErrCorruption) {
bmgrLog.Errorf("Critical failure: %v", dbErr.Error())
}

Expand Down Expand Up @@ -2586,9 +2585,7 @@ func loadBlockDB(params *chaincfg.Params) (database.DB, error) {
// Return the error if it's not because the database doesn't
// exist.
var dbErr database.Error
if !errors.As(err, &dbErr) || dbErr.ErrorCode !=
database.ErrDbDoesNotExist {

if !errors.As(err, &dbErr) || !errors.Is(dbErr, database.ErrDbDoesNotExist) {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/addblock/addblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package main

import (
"errors"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -38,9 +39,8 @@ func loadBlockDB() (database.DB, error) {
if err != nil {
// Return the error if it's not because the database doesn't
// exist.
if dbErr, ok := err.(database.Error); !ok || dbErr.ErrorCode !=
database.ErrDbDoesNotExist {

var dbErr database.Error
if !errors.As(err, &dbErr) || !errors.Is(dbErr, database.ErrDbDoesNotExist) {
return nil, err
}

Expand Down
5 changes: 3 additions & 2 deletions database/cmd/dbtool/insecureimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"encoding/binary"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -376,8 +377,8 @@ func (cmd *importCmd) Execute(args []string) error {
resultsChan := importer.Import()
results := <-resultsChan
if results.err != nil {
dbErr, ok := results.err.(database.Error)
if !ok || ok && dbErr.ErrorCode != database.ErrDbNotOpen {
var dbErr database.Error
if !errors.As(results.err, &dbErr) || !errors.Is(dbErr, database.ErrDbNotOpen) {
shutdownChannel <- results.err
return
}
Expand Down
6 changes: 3 additions & 3 deletions database/cmd/dbtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package main

import (
"errors"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -37,9 +38,8 @@ func loadBlockDB() (database.DB, error) {
if err != nil {
// Return the error if it's not because the database doesn't
// exist.
if dbErr, ok := err.(database.Error); !ok || dbErr.ErrorCode !=
database.ErrDbDoesNotExist {

var dbErr database.Error
if !errors.As(err, &dbErr) || !errors.Is(dbErr, database.ErrDbDoesNotExist) {
return nil, err
}

Expand Down
Loading

0 comments on commit ef83ecd

Please sign in to comment.