Skip to content

Commit

Permalink
fix: add unhandled return error handling. (#782)
Browse files Browse the repository at this point in the history
* fix: add unhandled return error handling.

* chore: add changelog

Signed-off-by: zemyblue <[email protected]>

* chore: change error handling as if-clause case.

Signed-off-by: zemyblue <[email protected]>

* chore: rollback init_node.sh changes.

Signed-off-by: zemyblue <[email protected]>

* Update CHANGELOG.md

Co-authored-by: Youngtaek Yoon <[email protected]>

Signed-off-by: zemyblue <[email protected]>
Co-authored-by: Youngtaek Yoon <[email protected]>
  • Loading branch information
zemyblue and 0Tech authored Nov 8, 2022
1 parent 9c041c4 commit b845d33
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion baseapp/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion x/bank/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions x/feegrant/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion x/foundation/keeper/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion x/slashing/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
Expand Down
4 changes: 3 additions & 1 deletion x/slashing/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion x/staking/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion x/wasm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit b845d33

Please sign in to comment.