Skip to content

Commit

Permalink
fix(x/gov): Return ErrInvalidProposalContent in SubmitProposal when l…
Browse files Browse the repository at this point in the history
…egacy handler returns an error. (cosmos#13051)

* [13030]: When a legacy gov proposal fails it's handler check, wrap the error in a ErrInvalidProposalContent (instead of ErrNoProposalHandlerExists).

* [13030]: Add changelog entry.

* [13030]: If the error is already a ErrNoProposalHandlerExists, just return it. Otherwise, wrap it as a ErrInvalidProposalContent.

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
  • Loading branch information
SpicyLemon and alexanderbez authored Aug 26, 2022
1 parent fc7ee0b commit 20b947e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/upgrade) [#12906](https://github.com/cosmos/cosmos-sdk/pull/12906) Fix upgrade failure by moving downgrade verification logic after store migration.
* (store) [#12945](https://github.com/cosmos/cosmos-sdk/pull/12945) Fix nil end semantics in store/cachekv/iterator when iterating a dirty cache.
* (export) [#13029](https://github.com/cosmos/cosmos-sdk/pull/13029) Fix exporting the blockParams regression.
* (x/gov) [#13051](https://github.com/cosmos/cosmos-sdk/pull/13051) In SubmitPropsal, when a legacy msg fails it's handler call, wrap the error as ErrInvalidProposalContent (instead of ErrNoProposalHandlerExists).

### Deprecated

Expand Down
6 changes: 5 additions & 1 deletion x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"errors"
"fmt"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -54,7 +55,10 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat
if msg, ok := msg.(*v1.MsgExecLegacyContent); ok {
cacheCtx, _ := ctx.CacheContext()
if _, err := handler(cacheCtx, msg); err != nil {
return v1.Proposal{}, sdkerrors.Wrap(types.ErrNoProposalHandlerExists, err.Error())
if errors.Is(types.ErrNoProposalHandlerExists, err) {
return v1.Proposal{}, err
}
return v1.Proposal{}, sdkerrors.Wrap(types.ErrInvalidProposalContent, err.Error())
}
}

Expand Down

0 comments on commit 20b947e

Please sign in to comment.