From 1c4e1c2b93214f8213eaa414c012ffd11c7584a0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 16 Aug 2024 15:03:24 +0200 Subject: [PATCH] chore: fix all lint issue since golangci-lint bump (#21326) (cherry picked from commit 6276b015bbab06cf563a7e6ec5d8bbc85f7708cc) # Conflicts: # log/CHANGELOG.md # log/logger.go # tools/cosmovisor/cmd/cosmovisor/version_test.go --- .github/workflows/lint.yml | 1 + client/v2/autocli/keyring/keyring.go | 4 +- log/CHANGELOG.md | 67 ++++++ log/logger.go | 200 ++++++++++++++++++ simapp/simd/cmd/root_di.go | 2 +- tests/integration/slashing/slashing_test.go | 2 +- tests/systemtests/system.go | 2 +- .../cosmovisor/cmd/cosmovisor/version_test.go | 27 +++ x/auth/keeper/grpc_query.go | 8 +- x/authz/keeper/grpc_query.go | 8 +- x/distribution/keeper/grpc_query.go | 4 +- x/distribution/keeper/msg_server.go | 2 +- x/evidence/keeper/grpc_query.go | 2 +- x/feegrant/keeper/grpc_query.go | 4 +- x/gov/keeper/msg_server.go | 2 +- x/gov/keeper/proposal.go | 4 +- x/group/client/cli/tx.go | 2 +- x/group/keeper/keeper.go | 2 +- x/slashing/keeper/signing_info.go | 2 +- x/upgrade/keeper/abci_test.go | 4 +- 20 files changed, 323 insertions(+), 26 deletions(-) create mode 100644 log/CHANGELOG.md create mode 100644 log/logger.go create mode 100644 tools/cosmovisor/cmd/cosmovisor/version_test.go diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 004fdd39d550..28ec11d378cb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,6 +22,7 @@ jobs: id: git_diff with: PATTERNS: | + **/*.mk Makefile **/Makefile .golangci.yml diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index a838b12d8455..70c2d27d08ed 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -10,7 +10,9 @@ import ( // KeyringContextKey is the key used to store the keyring in the context. // The keyring must be wrapped using the KeyringImpl. -var KeyringContextKey struct{} +var KeyringContextKey keyringContextKey + +type keyringContextKey struct{} var _ Keyring = &KeyringImpl{} diff --git a/log/CHANGELOG.md b/log/CHANGELOG.md new file mode 100644 index 000000000000..c9f2475683e9 --- /dev/null +++ b/log/CHANGELOG.md @@ -0,0 +1,67 @@ + + +# Changelog + +## [Unreleased] + +## [v1.4.1](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.4.1) - 2024-08-16 + +* [#21326](https://github.com/cosmos/cosmos-sdk/pull/21326) Avoid context key collision. + +## [v1.4.0](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.4.0) - 2024-08-07 + +* [#21045](https://github.com/cosmos/cosmos-sdk/pull/21045) Add `WithContext` method implementations to make all returned loggers compatible with `cosmossdk.io/core/log.Logger` (v1) without a direct dependency. + +## [v1.3.1](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.3.1) - 2024-02-05 + +* [#19346](https://github.com/cosmos/cosmos-sdk/pull/19346) Upgrade zerolog to v1.32.0. +* [#19346](https://github.com/cosmos/cosmos-sdk/pull/19346) `#15956` now works thanks to the upgrade of `zerolog`. + +## [v1.3.0](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.3.0) - 2024-01-10 + +* [#18916](https://github.com/cosmos/cosmos-sdk/pull/18916) Introduce an option for setting hooks. +* [#18429](https://github.com/cosmos/cosmos-sdk/pull/18429) Support customization of log json marshal. +* [#18898](https://github.com/cosmos/cosmos-sdk/pull/18898) Add `WARN` level. + +## [v1.2.1](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.2.1) - 2023-08-25 + +* [#17532](https://github.com/cosmos/cosmos-sdk/pull/17532) Proper marshalling of `fmt.Stringer` (follow-up of [#17205](https://github.com/cosmos/cosmos-sdk/pull/17205)). + +## [v1.2.0](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.2.0) - 2023-07-31 + +* [#17194](https://github.com/cosmos/cosmos-sdk/pull/17194) Avoid repeating parse log level in `ParseLogLevel`. +* [#17205](https://github.com/cosmos/cosmos-sdk/pull/17205) Fix types that do not implement the `json.Marshaler` interface. +* [#15956](https://github.com/cosmos/cosmos-sdk/pull/15956) Introduce an option for enabling error stack trace. + +## [v1.1.0](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.1.0) - 2023-04-27 + +* [#15956](https://github.com/cosmos/cosmos-sdk/pull/15956) Introduce options to configure logger (enable/disable colored output, customize log timestamps). + +## [v1.0.0](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.0.0) - 2023-03-30 + +* [#15601](https://github.com/cosmos/cosmos-sdk/pull/15601) Introduce logger options. These options allow to configure the logger with filters, different level and output format. + +## [v0.1.0](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v0.1.0) - 2023-03-13 + +* Introducing a standalone SDK logger package (`comossdk.io/log`). + It replaces CometBFT logger and provides a common interface for all SDK components. + The default logger (`NewLogger`) is using [zerolog](https://github.com/rs/zerolog), + but it can be easily replaced with any implementation that implements the `log.Logger` interface. diff --git a/log/logger.go b/log/logger.go new file mode 100644 index 000000000000..8a27538e80ff --- /dev/null +++ b/log/logger.go @@ -0,0 +1,200 @@ +package log + +import ( + "encoding" + "encoding/json" + "fmt" + "io" + + "github.com/pkg/errors" + "github.com/rs/zerolog" + "github.com/rs/zerolog/pkgerrors" +) + +func init() { + zerolog.InterfaceMarshalFunc = func(i any) ([]byte, error) { + switch v := i.(type) { + case json.Marshaler: + return json.Marshal(i) + case encoding.TextMarshaler: + return json.Marshal(i) + case fmt.Stringer: + return json.Marshal(v.String()) + default: + return json.Marshal(i) + } + } +} + +// ModuleKey defines a module logging key. +const ModuleKey = "module" + +// ContextKey is used to store the logger in the context. +var ContextKey contextKey + +type contextKey struct{} + +// Logger is the Cosmos SDK logger interface. +// It extends cosmossdk.io/core/log.Logger to return a child logger. +// Use cosmossdk.io/core/log.Logger instead in modules. +type Logger interface { + // Info takes a message and a set of key/value pairs and logs with level INFO. + // The key of the tuple must be a string. + Info(msg string, keyVals ...any) + + // Warn takes a message and a set of key/value pairs and logs with level WARN. + // The key of the tuple must be a string. + Warn(msg string, keyVals ...any) + + // Error takes a message and a set of key/value pairs and logs with level ERR. + // The key of the tuple must be a string. + Error(msg string, keyVals ...any) + + // Debug takes a message and a set of key/value pairs and logs with level DEBUG. + // The key of the tuple must be a string. + Debug(msg string, keyVals ...any) + + // With returns a new wrapped logger with additional context provided by a set. + With(keyVals ...any) Logger + + // Impl returns the underlying logger implementation. + // It is used to access the full functionalities of the underlying logger. + // Advanced users can type cast the returned value to the actual logger. + Impl() any +} + +// WithJSONMarshal configures zerolog global json encoding. +func WithJSONMarshal(marshaler func(v any) ([]byte, error)) { + zerolog.InterfaceMarshalFunc = func(i any) ([]byte, error) { + switch v := i.(type) { + case json.Marshaler: + return marshaler(i) + case encoding.TextMarshaler: + return marshaler(i) + case fmt.Stringer: + return marshaler(v.String()) + default: + return marshaler(i) + } + } +} + +type zeroLogWrapper struct { + *zerolog.Logger +} + +// NewLogger returns a new logger that writes to the given destination. +// +// Typical usage from a main function is: +// +// logger := log.NewLogger(os.Stderr) +// +// Stderr is the typical destination for logs, +// so that any output from your application can still be piped to other processes. +// The returned value can be safely cast to cosmossdk.io/core/log.Logger. +func NewLogger(dst io.Writer, options ...Option) Logger { + logCfg := defaultConfig + for _, opt := range options { + opt(&logCfg) + } + + output := dst + if !logCfg.OutputJSON { + output = zerolog.ConsoleWriter{ + Out: dst, + NoColor: !logCfg.Color, + TimeFormat: logCfg.TimeFormat, + } + } + + if logCfg.Filter != nil { + output = NewFilterWriter(output, logCfg.Filter) + } + + logger := zerolog.New(output) + if logCfg.StackTrace { + zerolog.ErrorStackMarshaler = func(err error) interface{} { + return pkgerrors.MarshalStack(errors.WithStack(err)) + } + + logger = logger.With().Stack().Logger() + } + + if logCfg.TimeFormat != "" { + logger = logger.With().Timestamp().Logger() + } + + if logCfg.Level != zerolog.NoLevel { + logger = logger.Level(logCfg.Level) + } + + logger = logger.Hook(logCfg.Hooks...) + + return zeroLogWrapper{&logger} +} + +// NewCustomLogger returns a new logger with the given zerolog logger. +func NewCustomLogger(logger zerolog.Logger) Logger { + return zeroLogWrapper{&logger} +} + +// Info takes a message and a set of key/value pairs and logs with level INFO. +// The key of the tuple must be a string. +func (l zeroLogWrapper) Info(msg string, keyVals ...interface{}) { + l.Logger.Info().Fields(keyVals).Msg(msg) +} + +// Warn takes a message and a set of key/value pairs and logs with level WARN. +// The key of the tuple must be a string. +func (l zeroLogWrapper) Warn(msg string, keyVals ...interface{}) { + l.Logger.Warn().Fields(keyVals).Msg(msg) +} + +// Error takes a message and a set of key/value pairs and logs with level ERROR. +// The key of the tuple must be a string. +func (l zeroLogWrapper) Error(msg string, keyVals ...interface{}) { + l.Logger.Error().Fields(keyVals).Msg(msg) +} + +// Debug takes a message and a set of key/value pairs and logs with level DEBUG. +// The key of the tuple must be a string. +func (l zeroLogWrapper) Debug(msg string, keyVals ...interface{}) { + l.Logger.Debug().Fields(keyVals).Msg(msg) +} + +// With returns a new wrapped logger with additional context provided by a set. +func (l zeroLogWrapper) With(keyVals ...interface{}) Logger { + logger := l.Logger.With().Fields(keyVals).Logger() + return zeroLogWrapper{&logger} +} + +// WithContext returns a new wrapped logger with additional context provided by a set. +func (l zeroLogWrapper) WithContext(keyVals ...interface{}) any { + logger := l.Logger.With().Fields(keyVals).Logger() + return zeroLogWrapper{&logger} +} + +// Impl returns the underlying zerolog logger. +// It can be used to used zerolog structured API directly instead of the wrapper. +func (l zeroLogWrapper) Impl() interface{} { + return l.Logger +} + +// NewNopLogger returns a new logger that does nothing. +func NewNopLogger() Logger { + // The custom nopLogger is about 3x faster than a zeroLogWrapper with zerolog.Nop(). + return nopLogger{} +} + +// nopLogger is a Logger that does nothing when called. +// See the "specialized nop logger" benchmark and compare with the "zerolog nop logger" benchmark. +// The custom implementation is about 3x faster. +type nopLogger struct{} + +func (nopLogger) Info(string, ...any) {} +func (nopLogger) Warn(string, ...any) {} +func (nopLogger) Error(string, ...any) {} +func (nopLogger) Debug(string, ...any) {} +func (nopLogger) With(...any) Logger { return nopLogger{} } +func (nopLogger) WithContext(...any) any { return nopLogger{} } +func (nopLogger) Impl() any { return nopLogger{} } diff --git a/simapp/simd/cmd/root_di.go b/simapp/simd/cmd/root_di.go index 640ebdf1c5fd..863835f7d979 100644 --- a/simapp/simd/cmd/root_di.go +++ b/simapp/simd/cmd/root_di.go @@ -19,10 +19,10 @@ import ( "cosmossdk.io/x/auth/tx" authtxconfig "cosmossdk.io/x/auth/tx/config" "cosmossdk.io/x/auth/types" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server" diff --git a/tests/integration/slashing/slashing_test.go b/tests/integration/slashing/slashing_test.go index bec39e2449f8..36d9ec53e493 100644 --- a/tests/integration/slashing/slashing_test.go +++ b/tests/integration/slashing/slashing_test.go @@ -114,5 +114,5 @@ func TestSlashingMsgs(t *testing.T) { headerInfo = header.Info{Height: app.LastBlockHeight() + 1} _, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, headerInfo, []sdk.Msg{unjailMsg}, "", []uint64{0}, []uint64{1}, false, false, priv1) require.Error(t, err) - require.True(t, errors.Is(types.ErrValidatorNotJailed, err)) + require.True(t, errors.Is(err, types.ErrValidatorNotJailed)) } diff --git a/tests/systemtests/system.go b/tests/systemtests/system.go index bc8f4351b33d..1c39cc150df5 100644 --- a/tests/systemtests/system.go +++ b/tests/systemtests/system.go @@ -247,7 +247,7 @@ func (s *SystemUnderTest) AwaitUpgradeInfo(t *testing.T) { case err == nil: found = true case !os.IsNotExist(err): - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } }) time.Sleep(s.blockTime / 2) diff --git a/tools/cosmovisor/cmd/cosmovisor/version_test.go b/tools/cosmovisor/cmd/cosmovisor/version_test.go new file mode 100644 index 000000000000..9f4cfb896072 --- /dev/null +++ b/tools/cosmovisor/cmd/cosmovisor/version_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "bytes" + "context" + "testing" + + "github.com/stretchr/testify/require" + + "cosmossdk.io/log" +) + +func TestVersionCommand_Error(t *testing.T) { + logger := log.NewTestLogger(t).With(log.ModuleKey, "cosmovisor") + + rootCmd := NewRootCmd() + rootCmd.SetArgs([]string{"version"}) + + out := bytes.NewBufferString("") + rootCmd.SetOut(out) + rootCmd.SetErr(out) + + ctx := context.WithValue(context.Background(), log.ContextKey, logger) //nolint:staticcheck // temporary issue in dependency + + require.Error(t, rootCmd.ExecuteContext(ctx)) + require.Contains(t, out.String(), "DAEMON_NAME is not set") +} diff --git a/x/auth/keeper/grpc_query.go b/x/auth/keeper/grpc_query.go index 6025b6f932b3..4305358c304f 100644 --- a/x/auth/keeper/grpc_query.go +++ b/x/auth/keeper/grpc_query.go @@ -86,7 +86,7 @@ func (s queryServer) Account(ctx context.Context, req *types.QueryAccountRequest any, err := codectypes.NewAnyWithValue(account) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } return &types.QueryAccountResponse{Account: any}, nil @@ -124,7 +124,7 @@ func (s queryServer) ModuleAccounts(ctx context.Context, req *types.QueryModuleA } any, err := codectypes.NewAnyWithValue(account) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } modAccounts = append(modAccounts, any) } @@ -150,7 +150,7 @@ func (s queryServer) ModuleAccountByName(ctx context.Context, req *types.QueryMo } any, err := codectypes.NewAnyWithValue(account) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } return &types.QueryModuleAccountByNameResponse{Account: any}, nil @@ -234,7 +234,7 @@ func (s queryServer) AccountInfo(ctx context.Context, req *types.QueryAccountInf if pubKey != nil { pkAny, err = codectypes.NewAnyWithValue(account.GetPubKey()) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } } diff --git a/x/authz/keeper/grpc_query.go b/x/authz/keeper/grpc_query.go index 4d73afac4e6c..89cb8ac67d65 100644 --- a/x/authz/keeper/grpc_query.go +++ b/x/authz/keeper/grpc_query.go @@ -48,7 +48,7 @@ func (k Keeper) Grants(ctx context.Context, req *authz.QueryGrantsRequest) (*aut authorizationAny, err := codectypes.NewAnyWithValue(authorization) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } return &authz.QueryGrantsResponse{ Grants: []*authz.Grant{{ @@ -70,7 +70,7 @@ func (k Keeper) Grants(ctx context.Context, req *authz.QueryGrantsRequest) (*aut authorizationAny, err := codectypes.NewAnyWithValue(auth1) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } return &authz.Grant{ Authorization: authorizationAny, @@ -111,7 +111,7 @@ func (k Keeper) GranterGrants(ctx context.Context, req *authz.QueryGranterGrants any, err := codectypes.NewAnyWithValue(auth1) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } grantee := firstAddressFromGrantStoreKey(key) @@ -166,7 +166,7 @@ func (k Keeper) GranteeGrants(ctx context.Context, req *authz.QueryGranteeGrants authorizationAny, err := codectypes.NewAnyWithValue(auth1) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } granterAddr, err := k.authKeeper.AddressCodec().BytesToString(granter) diff --git a/x/distribution/keeper/grpc_query.go b/x/distribution/keeper/grpc_query.go index de8657276fbe..5337ec58c342 100644 --- a/x/distribution/keeper/grpc_query.go +++ b/x/distribution/keeper/grpc_query.go @@ -119,7 +119,7 @@ func (k Querier) ValidatorOutstandingRewards(ctx context.Context, req *types.Que } if validator == nil { - return nil, errors.Wrapf(types.ErrNoValidatorExists, req.ValidatorAddress) + return nil, errors.Wrap(types.ErrNoValidatorExists, req.ValidatorAddress) } rewards, err := k.Keeper.ValidatorOutstandingRewards.Get(ctx, valAdr) @@ -151,7 +151,7 @@ func (k Querier) ValidatorCommission(ctx context.Context, req *types.QueryValida } if validator == nil { - return nil, errors.Wrapf(types.ErrNoValidatorExists, req.ValidatorAddress) + return nil, errors.Wrap(types.ErrNoValidatorExists, req.ValidatorAddress) } commission, err := k.ValidatorsAccumulatedCommission.Get(ctx, valAdr) if err != nil && !errors.IsOf(err, collections.ErrNotFound) { diff --git a/x/distribution/keeper/msg_server.go b/x/distribution/keeper/msg_server.go index 2b405f9b053a..0a4b9f32ca49 100644 --- a/x/distribution/keeper/msg_server.go +++ b/x/distribution/keeper/msg_server.go @@ -189,7 +189,7 @@ func (k msgServer) DepositValidatorRewardsPool(ctx context.Context, msg *types.M } if validator == nil { - return nil, errors.Wrapf(types.ErrNoValidatorExists, msg.ValidatorAddress) + return nil, errors.Wrap(types.ErrNoValidatorExists, msg.ValidatorAddress) } // Allocate tokens from the distribution module to the validator, which are diff --git a/x/evidence/keeper/grpc_query.go b/x/evidence/keeper/grpc_query.go index a665c820ce31..854dbbd33846 100644 --- a/x/evidence/keeper/grpc_query.go +++ b/x/evidence/keeper/grpc_query.go @@ -53,7 +53,7 @@ func (k Querier) Evidence(ctx context.Context, req *types.QueryEvidenceRequest) evidenceAny, err := codectypes.NewAnyWithValue(msg) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } return &types.QueryEvidenceResponse{Evidence: evidenceAny}, nil diff --git a/x/feegrant/keeper/grpc_query.go b/x/feegrant/keeper/grpc_query.go index 0bc3db1839cc..f5ff7df04370 100644 --- a/x/feegrant/keeper/grpc_query.go +++ b/x/feegrant/keeper/grpc_query.go @@ -35,7 +35,7 @@ func (q Keeper) Allowance(ctx context.Context, req *feegrant.QueryAllowanceReque feeAllowance, err := q.GetAllowance(ctx, granterAddr, granteeAddr) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } msg, ok := feeAllowance.(proto.Message) @@ -45,7 +45,7 @@ func (q Keeper) Allowance(ctx context.Context, req *feegrant.QueryAllowanceReque feeAllowanceAny, err := codectypes.NewAnyWithValue(msg) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } return &feegrant.QueryAllowanceResponse{ diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index ec3e33a44c3d..5c7b623f045f 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -383,7 +383,7 @@ func (k msgServer) SudoExec(ctx context.Context, msg *v1.MsgSudoExec) (*v1.MsgSu if err := k.BranchService.Execute(ctx, func(ctx context.Context) error { // TODO add route check here if err := k.MsgRouterService.CanInvoke(ctx, sdk.MsgTypeURL(sudoedMsg)); err != nil { - return errors.Wrapf(govtypes.ErrInvalidProposal, err.Error()) + return errors.Wrap(govtypes.ErrInvalidProposal, err.Error()) } msgResp, err = k.MsgRouterService.InvokeUntyped(ctx, sudoedMsg) diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 4f378e6fcab9..d095d7053ae6 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -83,9 +83,9 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata if !bytes.Equal(signers[0], k.GetGovernanceAccount(ctx).GetAddress()) { addr, err := k.authKeeper.AddressCodec().BytesToString(signers[0]) if err != nil { - return v1.Proposal{}, errorsmod.Wrapf(types.ErrInvalidSigner, err.Error()) + return v1.Proposal{}, errorsmod.Wrap(types.ErrInvalidSigner, err.Error()) } - return v1.Proposal{}, errorsmod.Wrapf(types.ErrInvalidSigner, addr) + return v1.Proposal{}, errorsmod.Wrap(types.ErrInvalidSigner, addr) } if err := k.MsgRouterService.CanInvoke(ctx, sdk.MsgTypeURL(msg)); err != nil { diff --git a/x/group/client/cli/tx.go b/x/group/client/cli/tx.go index 52c998ebed60..0578b24dfff4 100644 --- a/x/group/client/cli/tx.go +++ b/x/group/client/cli/tx.go @@ -498,7 +498,7 @@ metadata example: // Since the --from flag is not required on this CLI command, we // ignore it, and just use the 1st proposer in the JSON file. - if prop.Proposers == nil || len(prop.Proposers) == 0 { + if len(prop.Proposers) == 0 { return errors.New("no proposers specified in proposal") } err = cmd.Flags().Set(flags.FlagFrom, prop.Proposers[0]) diff --git a/x/group/keeper/keeper.go b/x/group/keeper/keeper.go index 667c62ab0bc1..b1fc76f920cc 100644 --- a/x/group/keeper/keeper.go +++ b/x/group/keeper/keeper.go @@ -455,7 +455,7 @@ func (k Keeper) TallyProposalsAtVPEnd(ctx context.Context) error { // is greater than defined MaxMetadataLen in the module configuration func (k Keeper) assertMetadataLength(metadata, description string) error { if uint64(len(metadata)) > k.config.MaxMetadataLen { - return errors.ErrMetadataTooLong.Wrapf(description) + return errors.ErrMetadataTooLong.Wrap(description) } return nil } diff --git a/x/slashing/keeper/signing_info.go b/x/slashing/keeper/signing_info.go index 352590e24e73..64e4b7421066 100644 --- a/x/slashing/keeper/signing_info.go +++ b/x/slashing/keeper/signing_info.go @@ -31,7 +31,7 @@ func (k Keeper) JailUntil(ctx context.Context, consAddr sdk.ConsAddress, jailTim if err != nil { return types.ErrNoSigningInfoFound.Wrapf("could not convert consensus address to string. Error: %s", err.Error()) } - return types.ErrNoSigningInfoFound.Wrapf(fmt.Sprintf("cannot jail validator with consensus address %s that does not have any signing information", addr)) + return types.ErrNoSigningInfoFound.Wrapf("cannot jail validator with consensus address %s that does not have any signing information", addr) } signInfo.JailedUntil = jailTime diff --git a/x/upgrade/keeper/abci_test.go b/x/upgrade/keeper/abci_test.go index 4360a37797c1..c55d47fe0e73 100644 --- a/x/upgrade/keeper/abci_test.go +++ b/x/upgrade/keeper/abci_test.go @@ -148,7 +148,7 @@ func TestRequireFutureBlock(t *testing.T) { s := setupTest(t, 10, map[int64]bool{}) err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height - 1}) require.Error(t, err) - require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err) + require.True(t, errors.Is(err, sdkerrors.ErrInvalidRequest), err) } func TestDoHeightUpgrade(t *testing.T) { @@ -223,7 +223,7 @@ func TestCantApplySameUpgradeTwice(t *testing.T) { t.Log("Verify an executed upgrade \"test\" can't be rescheduled") err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: height}) require.Error(t, err) - require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err) + require.True(t, errors.Is(err, sdkerrors.ErrInvalidRequest), err) } func TestNoSpuriousUpgrades(t *testing.T) {