From b845d33914a41d598727ed178ddf27871b1cc9cf Mon Sep 17 00:00:00 2001 From: zemyblue Date: Tue, 8 Nov 2022 13:40:32 +0900 Subject: [PATCH] fix: add unhandled return error handling. (#782) * fix: add unhandled return error handling. * chore: add changelog Signed-off-by: zemyblue * chore: change error handling as if-clause case. Signed-off-by: zemyblue * chore: rollback init_node.sh changes. Signed-off-by: zemyblue * Update CHANGELOG.md Co-authored-by: Youngtaek Yoon Signed-off-by: zemyblue Co-authored-by: Youngtaek Yoon --- CHANGELOG.md | 1 + baseapp/grpcserver.go | 4 +++- server/start.go | 4 +++- server/util.go | 8 ++++++-- x/auth/client/rest/query.go | 5 ++++- x/bank/client/cli/tx.go | 4 +++- x/feegrant/client/cli/tx.go | 8 ++++++-- x/foundation/keeper/member.go | 4 +++- x/slashing/genesis.go | 4 +++- x/slashing/keeper/hooks.go | 4 +++- x/staking/genesis.go | 4 +++- x/staking/keeper/msg_server.go | 4 +++- x/wasm/client/cli/query.go | 4 +++- 13 files changed, 44 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5973ab077f..d1d95f6407 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * (x/foundation) [\#772](https://github.com/line/lbm-sdk/pull/772) export x/foundation pool * (baseapp) [\#781](https://github.com/line/lbm-sdk/pull/781) implement method `SetOption()` in baseapp +* (global) [\#782](https://github.com/line/lbm-sdk/pull/782) add unhandled return error handling ### Breaking Changes * (cli) [\#773](https://github.com/line/lbm-sdk/pull/773) guide users to use generate-only in messages for x/foundation authority diff --git a/baseapp/grpcserver.go b/baseapp/grpcserver.go index 1e9f76dc97..ba4e136f5f 100644 --- a/baseapp/grpcserver.go +++ b/baseapp/grpcserver.go @@ -61,7 +61,9 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { grpcCtx = context.WithValue(grpcCtx, sdk.SdkContextKey, sdkCtx) md = metadata.Pairs(grpctypes.GRPCBlockHeightHeader, strconv.FormatInt(height, 10)) - grpc.SetHeader(grpcCtx, md) + if err = grpc.SetHeader(grpcCtx, md); err != nil { + return nil, err + } return handler(grpcCtx, req) } diff --git a/server/start.go b/server/start.go index de08709d8c..30202a20ae 100644 --- a/server/start.go +++ b/server/start.go @@ -112,7 +112,9 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. // Bind flags to the Context's Viper so the app construction can set // options accordingly. - serverCtx.Viper.BindPFlags(cmd.Flags()) + if err := serverCtx.Viper.BindPFlags(cmd.Flags()); err != nil { + return err + } _, err := GetPruningOptionsFromFlags(serverCtx.Viper) return err diff --git a/server/util.go b/server/util.go index 70f72eab7f..36adeebe79 100644 --- a/server/util.go +++ b/server/util.go @@ -120,8 +120,12 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s basename := path.Base(executableName) // Configure the viper instance - serverCtx.Viper.BindPFlags(cmd.Flags()) - serverCtx.Viper.BindPFlags(cmd.PersistentFlags()) + if err = serverCtx.Viper.BindPFlags(cmd.Flags()); err != nil { + return err + } + if err = serverCtx.Viper.BindPFlags(cmd.PersistentFlags()); err != nil { + return err + } serverCtx.Viper.SetEnvPrefix(basename) serverCtx.Viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) serverCtx.Viper.AutomaticEnv() diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 53c82eac44..0fd7f554a3 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -103,7 +103,10 @@ func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { } for _, txRes := range searchResult.Txs { - packStdTxResponse(w, clientCtx, txRes) + if err = packStdTxResponse(w, clientCtx, txRes); err != nil { + // Error is already returned by packStdTxResponse. + return + } } err = checkAminoMarshalError(clientCtx, searchResult, "/cosmos/tx/v1beta1/txs") diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 51998c55ba..5cc3974092 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -33,7 +33,9 @@ func NewSendTxCmd() *cobra.Command { ignored as it is implied from [from_key_or_address].`, Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - cmd.Flags().Set(flags.FlagFrom, args[0]) + if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil { + return err + } clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err diff --git a/x/feegrant/client/cli/tx.go b/x/feegrant/client/cli/tx.go index 2440cc0866..20fc750d96 100644 --- a/x/feegrant/client/cli/tx.go +++ b/x/feegrant/client/cli/tx.go @@ -64,7 +64,9 @@ Examples: Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - cmd.Flags().Set(flags.FlagFrom, args[0]) + if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil { + return err + } clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -195,7 +197,9 @@ Example: ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - cmd.Flags().Set(flags.FlagFrom, args[0]) + if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil { + return err + } clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err diff --git a/x/foundation/keeper/member.go b/x/foundation/keeper/member.go index 58cb3c5dd4..69b7ebd999 100644 --- a/x/foundation/keeper/member.go +++ b/x/foundation/keeper/member.go @@ -16,7 +16,9 @@ func validateMetadata(metadata string, config foundation.Config) error { func (k Keeper) UpdateDecisionPolicy(ctx sdk.Context, policy foundation.DecisionPolicy) error { info := k.GetFoundationInfo(ctx) - info.SetDecisionPolicy(policy) + if err := info.SetDecisionPolicy(policy); err != nil { + return err + } info.Version++ k.SetFoundationInfo(ctx, info) diff --git a/x/slashing/genesis.go b/x/slashing/genesis.go index 7e8704d011..312afa1685 100644 --- a/x/slashing/genesis.go +++ b/x/slashing/genesis.go @@ -16,7 +16,9 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.Stak if err != nil { panic(err) } - keeper.AddPubkey(ctx, consPk) + if err = keeper.AddPubkey(ctx, consPk); err != nil { + panic(err) + } return false }, ) diff --git a/x/slashing/keeper/hooks.go b/x/slashing/keeper/hooks.go index b0dec933e0..7bc1565e9b 100644 --- a/x/slashing/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -32,7 +32,9 @@ func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) e if err != nil { return err } - k.AddPubkey(ctx, consPk) + if err = k.AddPubkey(ctx, consPk); err != nil { + return err + } return nil } diff --git a/x/staking/genesis.go b/x/staking/genesis.go index eaad4e4e0a..65c00f1b71 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -39,7 +39,9 @@ func InitGenesis( keeper.SetValidator(ctx, validator) // Manually set indices for the first time - keeper.SetValidatorByConsAddr(ctx, validator) + if err := keeper.SetValidatorByConsAddr(ctx, validator); err != nil { + panic(err) + } keeper.SetValidatorByPowerIndex(ctx, validator) // Call the creation hook if not exported diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 110fecc31d..373175b77d 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -92,7 +92,9 @@ func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateVa validator.MinSelfDelegation = msg.MinSelfDelegation k.SetValidator(ctx, validator) - k.SetValidatorByConsAddr(ctx, validator) + if err = k.SetValidatorByConsAddr(ctx, validator); err != nil { + return nil, err + } k.SetNewValidatorByPowerIndex(ctx, validator) // call the after-creation hook diff --git a/x/wasm/client/cli/query.go b/x/wasm/client/cli/query.go index 8f976e95f3..36d2320a41 100644 --- a/x/wasm/client/cli/query.go +++ b/x/wasm/client/cli/query.go @@ -538,7 +538,9 @@ func withPageKeyDecoded(flagSet *flag.FlagSet) *flag.FlagSet { if err != nil { panic(err.Error()) } - flagSet.Set(flags.FlagPageKey, string(raw)) + if err = flagSet.Set(flags.FlagPageKey, string(raw)); err != nil { + panic(err.Error()) + } return flagSet }