firefly-cli icon indicating copy to clipboard operation
firefly-cli copied to clipboard

Usage info should not be dumped for errors that don't relate to usage

Open awrichar opened this issue 4 years ago • 3 comments
trafficstars

The "usage" info for the active CLI command is always dumped when an error is encountered. This should only be dumped for errors that stem from invalid syntax, not from functional errors executing the command.

awrichar avatar Jun 03 '21 21:06 awrichar

This is a good suggestion. The reason it works the way it does is that any error returned from a Cobra RunE() will print usage by default. So we'll need to handle errors at the top level differently.

nguyer avatar Jun 10 '21 12:06 nguyer

I can pickup this one.

apoorvam1 avatar Oct 01 '21 21:10 apoorvam1

Here's my finding: We need to suppress usage info for internal errors with cmd.SilenceUsage = true and not call the cobra.CheckErr() function here explicitly https://github.com/hyperledger/firefly-cli/blob/main/cmd/root.go#L85 as it results in printing the error message twice.

When there is an error, cobra library prints the error message by default.

apoorvam1 avatar Oct 01 '21 23:10 apoorvam1