Merge PR #5421: Refactor Error Handling

This commit is contained in:
Alexander Bezobchuk
2019-12-27 12:57:54 -05:00
committed by GitHub
parent 3c82b66347
commit 9a183ffbcc
170 changed files with 2317 additions and 2934 deletions
+6 -6
View File
@@ -2,6 +2,7 @@ package mock
import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
@@ -49,10 +50,10 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) {
// KVStoreHandler is a simple handler that takes kvstoreTx and writes
// them to the db
func KVStoreHandler(storeKey sdk.StoreKey) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
dTx, ok := msg.(kvstoreTx)
if !ok {
panic("KVStoreHandler should only receive kvstoreTx")
return nil, errors.New("KVStoreHandler should only receive kvstoreTx")
}
// tx is already unmarshalled
@@ -62,10 +63,9 @@ func KVStoreHandler(storeKey sdk.StoreKey) sdk.Handler {
store := ctx.KVStore(storeKey)
store.Set(key, value)
return sdk.Result{
Code: 0,
Log: fmt.Sprintf("set %s=%s", key, value),
}
return &sdk.Result{
Log: fmt.Sprintf("set %s=%s", key, value),
}, nil
}
}
+4 -3
View File
@@ -6,6 +6,7 @@ import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// An sdk.Tx which is its own sdk.Msg.
@@ -47,7 +48,7 @@ func (tx kvstoreTx) GetSignBytes() []byte {
}
// Should the app be calling this? Or only handlers?
func (tx kvstoreTx) ValidateBasic() sdk.Error {
func (tx kvstoreTx) ValidateBasic() error {
return nil
}
@@ -57,7 +58,7 @@ func (tx kvstoreTx) GetSigners() []sdk.AccAddress {
// takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has
// all the signatures and can be used to authenticate.
func decodeTx(txBytes []byte) (sdk.Tx, sdk.Error) {
func decodeTx(txBytes []byte) (sdk.Tx, error) {
var tx sdk.Tx
split := bytes.Split(txBytes, []byte("="))
@@ -68,7 +69,7 @@ func decodeTx(txBytes []byte) (sdk.Tx, sdk.Error) {
k, v := split[0], split[1]
tx = kvstoreTx{k, v, txBytes}
} else {
return nil, sdk.ErrTxDecode("too many =")
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "too many '='")
}
return tx, nil