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 bbolt keys and bbolt get to prevent them from panicking when no parameter provided #682

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

Elbehery
Copy link
Member

resolves #681

cc @ahrtr

@Elbehery
Copy link
Member Author

@ahrtr i will go through all the cmds now

just this is to get early review

@Elbehery
Copy link
Member Author

only get & keys cmds having this issue .. fixed both 👍🏽

@ahrtr
Copy link
Member

ahrtr commented Jan 30, 2024

Just as we talked in the meeting, the fix overall looks good. The only concern is on the output, which mixes the error message and the command usage. We should only need to take care of the error message, and let the command generic utility to take care of the usage.

Output of this PR

$ ./bbolt get
expected arguments are 'database path', 'bucket', and 'key': not enough arguments

$ ./bbolt keys
required arguments are 'database', and 'bucket': not enough arguments

Good example of other commands

$ ./bbolt surgery clear-page 
Error: db file path not provided
Usage:
  bbolt surgery clear-page <bbolt-file> [options] [flags]

Flags:
  -h, --help            help for clear-page
      --output string   path to the filePath db file
      --pageId uint     page Id

@Elbehery
Copy link
Member Author

@ahrtr fixed, now the output

  • keys cmd
 ./bbolt keys
usage: bolt keys PATH [BUCKET...]

Print a list of keys in the given (sub)bucket.
=======

Additional options include:

        --format
                Output format. One of: auto|ascii-encoded|hex|bytes|redacted (default=auto)

Print a list of keys in the given bucket.

Error: not enough arguments.
  • get cmd
 ./bbolt get          
usage: bolt get PATH [BUCKET..] KEY

Print the value of the given key in the given (sub)bucket.

Additional options include:

        --format
                Output format. One of: auto|ascii-encoded|hex|bytes|redacted (default=auto)
        --parse-format
                Input format (of key). One of: ascii-encoded|hex (default=ascii-encoded)"

Error: not enough arguments.

Comment on lines 928 to 930
err := fmt.Errorf("Error: %w.\n", ErrNotEnoughArgs)
fmt.Fprintln(cmd.Stderr, cmd.Usage())
return err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := fmt.Errorf("Error: %w.\n", ErrNotEnoughArgs)
fmt.Fprintln(cmd.Stderr, cmd.Usage())
return err
return ErrNotEnoughArgs

Copy link
Member Author

Choose a reason for hiding this comment

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

updated, but this way the usage will not be printed

Copy link
Member

Choose a reason for hiding this comment

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

Your previous implement (see below) isn't consistent with the cobra style command's output.

Overall it isn't a big deal for now. Let's refactor it in future.

$ ./bbolt keys
usage: bolt keys PATH [BUCKET...]

Print a list of keys in the given (sub)bucket.
=======

Additional options include:

	--format
		Output format. One of: auto|ascii-encoded|hex|bytes|redacted (default=auto)

Print a list of keys in the given bucket.

Error: not enough arguments.

Comment on lines 1012 to 1014
err := fmt.Errorf("Error: %w.\n", ErrNotEnoughArgs)
fmt.Fprintln(cmd.Stderr, cmd.Usage())
return err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := fmt.Errorf("Error: %w.\n", ErrNotEnoughArgs)
fmt.Fprintln(cmd.Stderr, cmd.Usage())
return err
return ErrNotEnoughArgs

Copy link
Member Author

Choose a reason for hiding this comment

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

ditto

@ahrtr
Copy link
Member

ahrtr commented Jan 31, 2024

There are some inconsistency between the legacy commands and cobra style commands, we will need to do some refactor in future after we cut release-1.4 branch.

@Elbehery
Copy link
Member Author

sure, i will do the cobra migration as we discussed after the release 👍🏽

Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
@ahrtr ahrtr changed the title fix cli cmds panics Fix bbolt keys and bbolt get to prevent them from panicking when no parameter provided Jan 31, 2024
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

lgtm

Thanks

@ahrtr ahrtr merged commit 2ca3693 into etcd-io:main Feb 1, 2024
16 checks passed
@Elbehery Elbehery deleted the fix_cli_panics branch April 22, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

bbolt CLI util panics / shows not-user-friendly errors in certain cases with incorrect (number of) arguments
2 participants