Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): submit-legacy-proposal: return propoer error if no flag is provided #11287

Merged
merged 3 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (types) [\#11004](https://github.com/cosmos/cosmos-sdk/pull/11004) Added mutable versions of many of the sdk.Dec types operations. This improves performance when used by avoiding reallocating a new bigint for each operation.
* (x/auth) [\#10880](https://github.com/cosmos/cosmos-sdk/pull/10880) Added a new query to the tx query service that returns a block with transactions fully decoded.
* (types) [\#11200](https://github.com/cosmos/cosmos-sdk/pull/11200) Added `Min()` and `Max()` operations on sdk.Coins.
* (gov) [\#11287](https://github.com/cosmos/cosmos-sdk/pull/11287) Fix error message when no flags are provided while executing `submit-legacy-proposal` transaction.

### Bug Fixes

Expand Down
28 changes: 28 additions & 0 deletions x/gov/client/cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,41 @@ type legacyProposal struct {
Deposit string
}

func (p legacyProposal) validate() error {
if p.Type == "" {
return fmt.Errorf("proposal type is required")
}

if p.Title == "" {
return fmt.Errorf("proposal title is required")
}

if p.Description == "" {
return fmt.Errorf("proposal description is required")
}
return nil
}

func parseSubmitLegacyProposalFlags(fs *pflag.FlagSet) (*legacyProposal, error) {
proposal := &legacyProposal{}
proposalFile, _ := fs.GetString(FlagProposal)

if proposalFile == "" {
proposalType, _ := fs.GetString(FlagProposalType)
title, _ := fs.GetString(FlagTitle)
description, _ := fs.GetString(FlagDescription)
if proposalType == "" && title == "" && description == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this? validate is already doing this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this check to return a more user-friendly error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this error would say one of three have an issue but the other error would say specifically what the error is right?

return nil, fmt.Errorf("one of the --proposal or (--title, --description and --type) flags are required")
}

proposal.Title, _ = fs.GetString(FlagTitle)
proposal.Description, _ = fs.GetString(FlagDescription)
proposal.Type = govutils.NormalizeProposalType(proposalType)
proposal.Deposit, _ = fs.GetString(FlagDeposit)
if err := proposal.validate(); err != nil {
return nil, err
}

return proposal, nil
}

Expand All @@ -49,6 +73,10 @@ func parseSubmitLegacyProposalFlags(fs *pflag.FlagSet) (*legacyProposal, error)
return nil, err
}

if err := proposal.validate(); err != nil {
return nil, err
}

return proposal, nil
}

Expand Down
8 changes: 4 additions & 4 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const (
// Deprecated: only used for v1beta1 legacy proposals.
FlagProposalType = "type"
// Deprecated: only used for v1beta1 legacy proposals.
FlagDeposit = "deposit"
flagVoter = "voter"
flagDepositor = "depositor"
flagStatus = "status"
FlagDeposit = "deposit"
flagVoter = "voter"
flagDepositor = "depositor"
flagStatus = "status"
// Deprecated: only used for v1beta1 legacy proposals.
FlagProposal = "proposal"
)
Expand Down