Skip to content

Commit

Permalink
Merge PR #3557: Removing pkg/errors when not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni authored and jackzampolin committed Feb 8, 2019
1 parent 7bc837a commit ba63eb1
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 42 deletions.
3 changes: 2 additions & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"runtime/debug"
"strings"

"errors"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash"
Expand Down
6 changes: 3 additions & 3 deletions client/context/broadcast.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package context

import (
"github.com/pkg/errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -39,11 +39,11 @@ func (ctx CLIContext) BroadcastTxAndAwaitCommit(tx []byte) (sdk.TxResponse, erro
}

if !res.CheckTx.IsOK() {
return sdk.NewResponseFormatBroadcastTxCommit(res), errors.Errorf(res.CheckTx.Log)
return sdk.NewResponseFormatBroadcastTxCommit(res), fmt.Errorf(res.CheckTx.Log)
}

if !res.DeliverTx.IsOK() {
return sdk.NewResponseFormatBroadcastTxCommit(res), errors.Errorf(res.DeliverTx.Log)
return sdk.NewResponseFormatBroadcastTxCommit(res), fmt.Errorf(res.DeliverTx.Log)
}

return sdk.NewResponseFormatBroadcastTxCommit(res), err
Expand Down
6 changes: 3 additions & 3 deletions client/context/errors.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package context

import (
"github.com/pkg/errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// ErrInvalidAccount returns a standardized error reflecting that a given
// account address does not exist.
func ErrInvalidAccount(addr sdk.AccAddress) error {
return errors.Errorf(`No account with address %s was found in the state.
return fmt.Errorf(`No account with address %s was found in the state.
Are you sure there has been a transaction involving it?`, addr)
}

// ErrVerifyCommit returns a common error reflecting that the blockchain commit at a given
// height can't be verified. The reason is that the base checkpoint of the certifier is
// newer than the given height
func ErrVerifyCommit(height int64) error {
return errors.Errorf(`The height of base truststore in gaia-lite is higher than height %d.
return fmt.Errorf(`The height of base truststore in gaia-lite is higher than height %d.
Can't verify blockchain proof at this height. Please set --trust-node to true and try again`, height)
}
2 changes: 1 addition & 1 deletion client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, err erro

resp := result.Response
if !resp.IsOK() {
return res, errors.Errorf(resp.Log)
return res, errors.New(resp.Log)
}

// data from trusted node or subspace query doesn't need verification
Expand Down
5 changes: 3 additions & 2 deletions client/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"os"
"strings"

"errors"

"github.com/bgentry/speakeasy"
"github.com/mattn/go-isatty"
"github.com/pkg/errors"
)

// MinPassLength is the minimum acceptable password length
Expand Down Expand Up @@ -36,7 +37,7 @@ func GetPassword(prompt string, buf *bufio.Reader) (pass string, err error) {
if len(pass) < MinPassLength {
// Return the given password to the upstream client so it can handle a
// non-STDIN failure gracefully.
return pass, errors.Errorf("password must be at least %d characters", MinPassLength)
return pass, fmt.Errorf("password must be at least %d characters", MinPassLength)
}

return pass, nil
Expand Down
5 changes: 3 additions & 2 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"

"errors"

"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down Expand Up @@ -297,7 +298,7 @@ func printCreate(info keys.Info, showMnemonic bool, mnemonic string) error {
}
fmt.Fprintln(os.Stderr, string(jsonString))
default:
return errors.Errorf("I can't speak: %s", output)
return fmt.Errorf("I can't speak: %s", output)
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

"github.com/cosmos/cosmos-sdk/crypto/keys"

"errors"

"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/crypto/multisig"
Expand Down
7 changes: 3 additions & 4 deletions cmd/gaia/init/validate_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/types"
)
Expand All @@ -33,16 +32,16 @@ func ValidateGenesisCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {

var genDoc types.GenesisDoc
if genDoc, err = LoadGenesisDoc(cdc, genesis); err != nil {
return errors.Errorf("Error loading genesis doc from %s: %s", genesis, err.Error())
return fmt.Errorf("Error loading genesis doc from %s: %s", genesis, err.Error())
}

var genstate app.GenesisState
if err = cdc.UnmarshalJSON(genDoc.AppState, &genstate); err != nil {
return errors.Errorf("Error unmarshaling genesis doc %s: %s", genesis, err.Error())
return fmt.Errorf("Error unmarshaling genesis doc %s: %s", genesis, err.Error())
}

if err = app.GaiaValidateGenesisState(genstate); err != nil {
return errors.Errorf("Error validating genesis file %s: %s", genesis, err.Error())
return fmt.Errorf("Error validating genesis file %s: %s", genesis, err.Error())
}

fmt.Printf("File at %s is a valid genesis file for gaiad\n", genesis)
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strings"

"github.com/pkg/errors"
"errors"

"github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
Expand Down
3 changes: 1 addition & 2 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package server
import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down Expand Up @@ -58,7 +57,7 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C
jailWhiteList := viper.GetStringSlice(flagJailWhitelist)
appState, validators, err := appExporter(ctx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList)
if err != nil {
return errors.Errorf("error exporting state: %v\n", err)
return fmt.Errorf("error exporting state: %v", err)
}

doc, err := tmtypes.GenesisDocFromFile(ctx.Config.GenesisFile())
Expand Down
5 changes: 3 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package server

import (
"github.com/pkg/errors"
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down Expand Up @@ -76,7 +77,7 @@ func startStandAlone(ctx *Context, appCreator AppCreator) error {

svr, err := server.NewServer(addr, "socket", app)
if err != nil {
return errors.Errorf("error creating listener: %v\n", err)
return fmt.Errorf("error creating listener: %v", err)
}

svr.SetLogger(ctx.Logger.With("module", "abci-server"))
Expand Down
3 changes: 2 additions & 1 deletion server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"syscall"
"time"

"github.com/pkg/errors"
"errors"

"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down
6 changes: 4 additions & 2 deletions x/auth/client/txbuilder/txbuilder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package context

import (
"fmt"
"strings"

crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
Expand All @@ -10,7 +11,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"

"github.com/pkg/errors"
"errors"

"github.com/spf13/viper"
)

Expand Down Expand Up @@ -179,7 +181,7 @@ func (bldr TxBuilder) WithAccountNumber(accnum uint64) TxBuilder {
func (bldr TxBuilder) Build(msgs []sdk.Msg) (StdSignMsg, error) {
chainID := bldr.chainID
if chainID == "" {
return StdSignMsg{}, errors.Errorf("chain ID required but not specified")
return StdSignMsg{}, fmt.Errorf("chain ID required but not specified")
}

fees := bldr.fees
Expand Down
5 changes: 3 additions & 2 deletions x/bank/client/cli/sendtx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
Expand All @@ -9,7 +11,6 @@ import (
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
"github.com/cosmos/cosmos-sdk/x/bank"

"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -53,7 +54,7 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {

// ensure account has enough coins
if !account.GetCoins().IsAllGTE(coins) {
return errors.Errorf("Address %s doesn't have enough coins to pay for this transaction.", from)
return fmt.Errorf("address %s doesn't have enough coins to pay for this transaction", from)
}

// build and sign the transaction, then broadcast to Tendermint
Expand Down
6 changes: 2 additions & 4 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"strconv"

"github.com/pkg/errors"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -101,7 +99,7 @@ $ gaiacli gov submit-proposal --title="Test Proposal" --description="My awesome

// ensure account has enough coins
if !account.GetCoins().IsAllGTE(amount) {
return errors.Errorf("Address %s doesn't have enough coins to pay for this transaction.", from)
return fmt.Errorf("address %s doesn't have enough coins to pay for this transaction", from)
}

proposalType, err := gov.ProposalTypeFromString(proposal.Type)
Expand Down Expand Up @@ -204,7 +202,7 @@ $ gaiacli tx gov deposit 1 10stake --from mykey

// ensure account has enough coins
if !account.GetCoins().IsAllGTE(amount) {
return errors.Errorf("Address %s doesn't have enough coins to pay for this transaction.", from)
return fmt.Errorf("address %s doesn't have enough coins to pay for this transaction", from)
}

msg := gov.NewMsgDeposit(from, proposalID, amount)
Expand Down
3 changes: 2 additions & 1 deletion x/gov/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"

"errors"

"github.com/gorilla/mux"
"github.com/pkg/errors"

govClientUtils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
)
Expand Down
4 changes: 1 addition & 3 deletions x/gov/depositsvotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/json"
"fmt"

"github.com/pkg/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -98,7 +96,7 @@ func VoteOptionFromString(str string) (VoteOption, error) {
case "NoWithVeto":
return OptionNoWithVeto, nil
default:
return VoteOption(0xff), errors.Errorf("'%s' is not a valid vote option", str)
return VoteOption(0xff), fmt.Errorf("'%s' is not a valid vote option", str)
}
}

Expand Down
6 changes: 2 additions & 4 deletions x/gov/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"strings"
"time"

"github.com/pkg/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -177,7 +175,7 @@ func ProposalTypeFromString(str string) (ProposalKind, error) {
case "SoftwareUpgrade":
return ProposalTypeSoftwareUpgrade, nil
default:
return ProposalKind(0xff), errors.Errorf("'%s' is not a valid proposal type", str)
return ProposalKind(0xff), fmt.Errorf("'%s' is not a valid proposal type", str)
}
}

Expand Down Expand Up @@ -278,7 +276,7 @@ func ProposalStatusFromString(str string) (ProposalStatus, error) {
case "":
return StatusNil, nil
default:
return ProposalStatus(0xff), errors.Errorf("'%s' is not a valid proposal status", str)
return ProposalStatus(0xff), fmt.Errorf("'%s' is not a valid proposal status", str)
}
}

Expand Down
6 changes: 3 additions & 3 deletions x/staking/client/cli/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cli

import (
"github.com/pkg/errors"
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -14,15 +14,15 @@ func getShares(sharesAmountStr string, delAddr sdk.AccAddress, valAddr sdk.ValAd
}

if !sharesAmount.GT(sdk.ZeroDec()) {
return sharesAmount, errors.Errorf("shares amount must be positive number (ex. 123, 1.23456789)")
return sharesAmount, errors.New("shares amount must be positive number (ex. 123, 1.23456789)")
}

return
}

func buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr string) (commission types.CommissionMsg, err error) {
if rateStr == "" || maxRateStr == "" || maxChangeRateStr == "" {
return commission, errors.Errorf("must specify all validator commission parameters")
return commission, errors.New("must specify all validator commission parameters")
}

rate, err := sdk.NewDecFromStr(rateStr)
Expand Down

0 comments on commit ba63eb1

Please sign in to comment.