replace errors.go with github.com/pkg/errors (2/2) (#3890)

* init of (2/2) common errors

* Remove instances of cmn.Error (2/2)

- Replace usage of cmnError and errorWrap
- ref #3862

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>

* comment wording

* simplify IsErrXXX functions

* log panic along with stopping the MConnection
This commit is contained in:
Marko
2019-08-11 21:03:40 +04:00
committed by Anton Kaliaev
parent 8dc39b69b7
commit 8a282a5fee
14 changed files with 75 additions and 88 deletions
+4 -2
View File
@@ -3,6 +3,8 @@ package lite
import (
"bytes"
"github.com/pkg/errors"
cmn "github.com/tendermint/tendermint/libs/common"
lerr "github.com/tendermint/tendermint/lite/errors"
"github.com/tendermint/tendermint/types"
@@ -63,7 +65,7 @@ func (bv *BaseVerifier) Verify(signedHeader types.SignedHeader) error {
// Do basic sanity checks.
err := signedHeader.ValidateBasic(bv.chainID)
if err != nil {
return cmn.ErrorWrap(err, "in verify")
return errors.Wrap(err, "in verify")
}
// Check commit signatures.
@@ -71,7 +73,7 @@ func (bv *BaseVerifier) Verify(signedHeader types.SignedHeader) error {
bv.chainID, signedHeader.Commit.BlockID,
signedHeader.Height, signedHeader.Commit)
if err != nil {
return cmn.ErrorWrap(err, "in verify")
return errors.Wrap(err, "in verify")
}
return nil
+13 -25
View File
@@ -3,7 +3,7 @@ package errors
import (
"fmt"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/pkg/errors"
)
//----------------------------------------
@@ -49,15 +49,12 @@ func (e errEmptyTree) Error() string {
// ErrCommitNotFound indicates that a the requested commit was not found.
func ErrCommitNotFound() error {
return cmn.ErrorWrap(errCommitNotFound{}, "")
return errors.Wrap(errCommitNotFound{}, "")
}
func IsErrCommitNotFound(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errCommitNotFound)
return ok
}
return false
_, ok := errors.Cause(err).(errCommitNotFound)
return ok
}
//-----------------
@@ -65,18 +62,15 @@ func IsErrCommitNotFound(err error) bool {
// ErrUnexpectedValidators indicates a validator set mismatch.
func ErrUnexpectedValidators(got, want []byte) error {
return cmn.ErrorWrap(errUnexpectedValidators{
return errors.Wrap(errUnexpectedValidators{
got: got,
want: want,
}, "")
}
func IsErrUnexpectedValidators(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errUnexpectedValidators)
return ok
}
return false
_, ok := errors.Cause(err).(errUnexpectedValidators)
return ok
}
//-----------------
@@ -84,28 +78,22 @@ func IsErrUnexpectedValidators(err error) bool {
// ErrUnknownValidators indicates that some validator set was missing or unknown.
func ErrUnknownValidators(chainID string, height int64) error {
return cmn.ErrorWrap(errUnknownValidators{chainID, height}, "")
return errors.Wrap(errUnknownValidators{chainID, height}, "")
}
func IsErrUnknownValidators(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errUnknownValidators)
return ok
}
return false
_, ok := errors.Cause(err).(errUnknownValidators)
return ok
}
//-----------------
// ErrEmptyTree
func ErrEmptyTree() error {
return cmn.ErrorWrap(errEmptyTree{}, "")
return errors.Wrap(errEmptyTree{}, "")
}
func IsErrEmptyTree(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errEmptyTree)
return ok
}
return false
_, ok := errors.Cause(err).(errEmptyTree)
return ok
}
+4 -7
View File
@@ -1,7 +1,7 @@
package proxy
import (
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/pkg/errors"
)
type errNoData struct{}
@@ -12,13 +12,10 @@ func (e errNoData) Error() string {
// IsErrNoData checks whether an error is due to a query returning empty data
func IsErrNoData(err error) bool {
if err_, ok := err.(cmn.Error); ok {
_, ok := err_.Data().(errNoData)
return ok
}
return false
_, ok := errors.Cause(err).(errNoData)
return ok
}
func ErrNoData() error {
return cmn.ErrorWrap(errNoData{}, "")
return errors.Wrap(errNoData{}, "")
}
+4 -3
View File
@@ -4,9 +4,10 @@ import (
"fmt"
"strings"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/pkg/errors"
"github.com/tendermint/tendermint/crypto/merkle"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/lite"
lerr "github.com/tendermint/tendermint/lite/errors"
rpcclient "github.com/tendermint/tendermint/rpc/client"
@@ -83,7 +84,7 @@ func GetWithProofOptions(prt *merkle.ProofRuntime, path string, key []byte, opts
kp = kp.AppendKey(resp.Key, merkle.KeyEncodingURL)
err = prt.VerifyValue(resp.Proof, signedHeader.AppHash, kp.String(), resp.Value)
if err != nil {
return nil, cmn.ErrorWrap(err, "Couldn't verify value proof")
return nil, errors.Wrap(err, "Couldn't verify value proof")
}
return &ctypes.ResultABCIQuery{Response: resp}, nil
} else {
@@ -92,7 +93,7 @@ func GetWithProofOptions(prt *merkle.ProofRuntime, path string, key []byte, opts
// XXX How do we encode the key into a string...
err = prt.VerifyAbsence(resp.Proof, signedHeader.AppHash, string(resp.Key))
if err != nil {
return nil, cmn.ErrorWrap(err, "Couldn't verify absence proof")
return nil, errors.Wrap(err, "Couldn't verify absence proof")
}
return &ctypes.ResultABCIQuery{Response: resp}, nil
}
+4 -3
View File
@@ -1,7 +1,8 @@
package proxy
import (
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/pkg/errors"
log "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/lite"
lclient "github.com/tendermint/tendermint/lite/client"
@@ -29,11 +30,11 @@ func NewVerifier(chainID, rootDir string, client lclient.SignStatusClient, logge
logger.Info("lite/proxy/NewVerifier found no trusted full commit, initializing from source from height 1...")
fc, err := source.LatestFullCommit(chainID, 1, 1)
if err != nil {
return nil, cmn.ErrorWrap(err, "fetching source full commit @ height 1")
return nil, errors.Wrap(err, "fetching source full commit @ height 1")
}
err = trust.SaveFullCommit(fc)
if err != nil {
return nil, cmn.ErrorWrap(err, "saving full commit to trusted")
return nil, errors.Wrap(err, "saving full commit to trusted")
}
}