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

refactor: refactoring Narg checks #12814

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ameeetgaikwad
Copy link

@ameeetgaikwad ameeetgaikwad commented Jan 7, 2025

Related Issues

#12790

Proposed Changes

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

@rvagg
Copy link
Member

rvagg commented Jan 8, 2025

@ameeetgaikwad I think we need to be a bit more complete with this, have a look for instances of ctx.Args (specifically cctx.Args() usually but ctx.Args is a good shortening that should catch variations), and then walk back in the commands to see if there is a check there. Doing this in cli and doing a quick browse of the initial results I can see slash-consensus seems to need a check for 2 but doesn't have one. evm.go has its own custom error method (if argc := cctx.Args().Len(); argc != 1 {) which we probably should make consistent and use the IncorrectNumArgs function (I'm not sure there's a good reason to do it this way, seems like copypasta code to me). I've only looked through the first few files and haven't even touched miner or worker. It would be good here to be a bit more exhaustive than just fixing the obvious ones.

@ameeetgaikwad
Copy link
Author

@ameeetgaikwad I think we need to be a bit more complete with this, have a look for instances of ctx.Args (specifically cctx.Args() usually but ctx.Args is a good shortening that should catch variations), and then walk back in the commands to see if there is a check there. Doing this in cli and doing a quick browse of the initial results I can see slash-consensus seems to need a check for 2 but doesn't have one. evm.go has its own custom error method (if argc := cctx.Args().Len(); argc != 1 {) which we probably should make consistent and use the IncorrectNumArgs function (I'm not sure there's a good reason to do it this way, seems like copypasta code to me). I've only looked through the first few files and haven't even touched miner or worker. It would be good here to be a bit more exhaustive than just fixing the obvious ones.

I'll go further deep into it!

@rvagg
Copy link
Member

rvagg commented Jan 14, 2025

@ameeetgaikwad as per my latest comments, could you do a quick scan over your edits and double-check that you're not editing ones that can take >=X args rather than just ==X

@ameeetgaikwad
Copy link
Author

@rvagg so I shouldn't be editing >=X or <=X args right? only the one which has ==X. Is that correct?

cli/multisig.go Outdated
@@ -399,7 +403,7 @@ var msigProposeCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if cctx.NArg() < 3 {
if cctx.NArg() != 3 {
Copy link
Member

Choose a reason for hiding this comment

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

check the block directly below this, this command has a bit of nuance, let's just leave it alone

Copy link
Author

Choose a reason for hiding this comment

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

should I replace the showHelp with IncorrectNumArgsWithHint the one we wrote above

Copy link
Member

Choose a reason for hiding this comment

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

no, this one's got too much nuance, leave multisig.go alone, it's got fairly sophisticated handling already

cli/multisig.go Outdated
@@ -521,7 +525,7 @@ var msigApproveCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if cctx.NArg() < 2 {
if cctx.NArg() != 2 {
Copy link
Member

Choose a reason for hiding this comment

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

ditto, but there's 2 more blocks below here; so these commands already strictly check their number of arguments, they just have nuance to the way they report the misuse, let's leave it alone

cli/multisig.go Outdated
@@ -658,7 +662,7 @@ var msigCancelCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if cctx.NArg() < 2 {
if cctx.NArg() != 2 {
Copy link
Member

Choose a reason for hiding this comment

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

and again, there's 2 blocks below this that handle other cases up to 6 arguments, let's leave it alone

@ameeetgaikwad ameeetgaikwad requested a review from rvagg February 4, 2025 20:00
@ameeetgaikwad
Copy link
Author

I have some doubts regarding some comments. I have mentioned them.

Also let me know if I have missed some scope of this refactor. I'll refactor those folders as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔎 Awaiting Review
Development

Successfully merging this pull request may close these issues.

2 participants