Skip to content

Commit

Permalink
Move all errors to types/errors.go
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Jan 20, 2022
1 parent 0a6e01a commit 69b2e66
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
4 changes: 2 additions & 2 deletions x/gov/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (k msgServer) ExecLegacyContent(goCtx context.Context, msg *v1beta2.MsgExec

content, err := v1beta2.LegacyContentFromMessage(msg)
if err != nil {
return nil, sdkerrors.Wrapf(v1beta1.ErrInvalidProposalContent, "%+v", err)
return nil, sdkerrors.Wrapf(types.ErrInvalidProposalContent, "%+v", err)
}

// Ensure that the content has a respective handler
Expand All @@ -101,7 +101,7 @@ func (k msgServer) ExecLegacyContent(goCtx context.Context, msg *v1beta2.MsgExec

handler := k.Keeper.legacyRouter.GetRoute(content.ProposalRoute())
if err := handler(ctx, content); err != nil {
return nil, sdkerrors.Wrapf(v1beta1.ErrInvalidProposalContent, "failed to run legacy handler %s, %+v", content.ProposalRoute(), err)
return nil, sdkerrors.Wrapf(types.ErrInvalidProposalContent, "failed to run legacy handler %s, %+v", content.ProposalRoute(), err)
}

return &v1beta2.MsgExecLegacyContentResponse{}, nil
Expand Down
7 changes: 4 additions & 3 deletions x/gov/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ var (
ErrUnknownProposal = sdkerrors.Register(ModuleName, 2, "unknown proposal")
ErrInactiveProposal = sdkerrors.Register(ModuleName, 3, "inactive proposal")
ErrAlreadyActiveProposal = sdkerrors.Register(ModuleName, 4, "proposal already active")
// Errors 5, 6 & 7 are reserved as legacy errors
// See x/gov/types/v1beta1/errors.go
// Errors 5 & 6 are legacy errors related to v1beta1.Proposal.
ErrInvalidProposalContent = sdkerrors.Register(ModuleName, 5, "invalid proposal content")
ErrInvalidProposalType = sdkerrors.Register(ModuleName, 6, "invalid proposal type")
ErrInvalidVote = sdkerrors.Register(ModuleName, 7, "invalid vote option")
ErrInvalidGenesis = sdkerrors.Register(ModuleName, 8, "invalid genesis state")
ErrNoProposalHandlerExists = sdkerrors.Register(ModuleName, 9, "no handler exists for proposal type")
ErrUnroutableProposalMsg = sdkerrors.Register(ModuleName, 10, "proposal message not recognized by router")
ErrNoProposalMsgs = sdkerrors.Register(ModuleName, 11, "no messages proposed")
ErrInvalidProposalMsg = sdkerrors.Register(ModuleName, 12, "invalid proposal message")
ErrInvalidSigner = sdkerrors.Register(ModuleName, 13, "expected gov account as only signer for proposal message")
ErrInvalidSignalMsg = sdkerrors.Register(ModuleName, 14, "signal message is invalid")
ErrInvalidVote = sdkerrors.Register(ModuleName, 15, "invalid vote option")
)
12 changes: 0 additions & 12 deletions x/gov/types/v1beta1/errors.go

This file was deleted.

14 changes: 7 additions & 7 deletions x/gov/types/v1beta1/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ func (m MsgSubmitProposal) ValidateBasic() error {

content := m.GetContent()
if content == nil {
return sdkerrors.Wrap(ErrInvalidProposalContent, "missing content")
return sdkerrors.Wrap(types.ErrInvalidProposalContent, "missing content")
}
if !IsValidProposalType(content.ProposalType()) {
return sdkerrors.Wrap(ErrInvalidProposalType, content.ProposalType())
return sdkerrors.Wrap(types.ErrInvalidProposalType, content.ProposalType())
}
if err := content.ValidateBasic(); err != nil {
return err
Expand Down Expand Up @@ -194,7 +194,7 @@ func (msg MsgVote) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid voter address: %s", err)
}
if !ValidVoteOption(msg.Option) {
return sdkerrors.Wrap(ErrInvalidVote, msg.Option.String())
return sdkerrors.Wrap(types.ErrInvalidVote, msg.Option.String())
}

return nil
Expand Down Expand Up @@ -243,21 +243,21 @@ func (msg MsgVoteWeighted) ValidateBasic() error {
usedOptions := make(map[VoteOption]bool)
for _, option := range msg.Options {
if !ValidWeightedVoteOption(option) {
return sdkerrors.Wrap(ErrInvalidVote, option.String())
return sdkerrors.Wrap(types.ErrInvalidVote, option.String())
}
totalWeight = totalWeight.Add(option.Weight)
if usedOptions[option.Option] {
return sdkerrors.Wrap(ErrInvalidVote, "Duplicated vote option")
return sdkerrors.Wrap(types.ErrInvalidVote, "Duplicated vote option")
}
usedOptions[option.Option] = true
}

if totalWeight.GT(sdk.NewDec(1)) {
return sdkerrors.Wrap(ErrInvalidVote, "Total weight overflow 1.00")
return sdkerrors.Wrap(types.ErrInvalidVote, "Total weight overflow 1.00")
}

if totalWeight.LT(sdk.NewDec(1)) {
return sdkerrors.Wrap(ErrInvalidVote, "Total weight lower than 1.00")
return sdkerrors.Wrap(types.ErrInvalidVote, "Total weight lower than 1.00")
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions x/gov/types/v1beta1/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,18 @@ func ValidProposalStatus(status ProposalStatus) bool {
func ValidateAbstract(c Content) error {
title := c.GetTitle()
if len(strings.TrimSpace(title)) == 0 {
return sdkerrors.Wrap(ErrInvalidProposalContent, "proposal title cannot be blank")
return sdkerrors.Wrap(types.ErrInvalidProposalContent, "proposal title cannot be blank")
}
if len(title) > MaxTitleLength {
return sdkerrors.Wrapf(ErrInvalidProposalContent, "proposal title is longer than max length of %d", MaxTitleLength)
return sdkerrors.Wrapf(types.ErrInvalidProposalContent, "proposal title is longer than max length of %d", MaxTitleLength)
}

description := c.GetDescription()
if len(description) == 0 {
return sdkerrors.Wrap(ErrInvalidProposalContent, "proposal description cannot be blank")
return sdkerrors.Wrap(types.ErrInvalidProposalContent, "proposal description cannot be blank")
}
if len(description) > MaxDescriptionLength {
return sdkerrors.Wrapf(ErrInvalidProposalContent, "proposal description is longer than max length of %d", MaxDescriptionLength)
return sdkerrors.Wrapf(types.ErrInvalidProposalContent, "proposal description is longer than max length of %d", MaxDescriptionLength)
}

return nil
Expand Down

0 comments on commit 69b2e66

Please sign in to comment.