docker / cli

The Docker CLI
Apache License 2.0
4.75k stars 1.88k forks source link

cli: make cli.StatusError slightly prettier #5231

Closed thaJeztah closed 5 days ago

thaJeztah commented 6 days ago

This error didn't do a great job at formatting. If a StatusError was produced without a Status message, it would print a very non-informative error, with information missing.

Let's update the output:

Before this patch, an error without custom status would print:

Status: , Code: 2

After this patch:

exit status 2

In situations where a custom error-message is provided, the error-message is print as-is, whereas before this patch, the message got combined with the Status: and Code:, which resulted in some odd output.

Before this patch:

docker volume --no-such-flag
Status: unknown flag: --no-such-flag
See 'docker volume --help'.

Usage:  docker volume COMMAND

Manage volumes

Commands:
  create      Create a volume
  inspect     Display detailed information on one or more volumes
  ls          List volumes
  prune       Remove unused local volumes
  rm          Remove one or more volumes
  update      Update a volume (cluster volumes only)

Run 'docker volume COMMAND --help' for more information on a command.
, Code: 125

With this patch, the error is shown as-is;

docker volume --no-such-flag
unknown flag: --no-such-flag
See 'docker volume --help'.

Usage:  docker volume COMMAND

Manage volumes

Commands:
  create      Create a volume
  inspect     Display detailed information on one or more volumes
  ls          List volumes
  prune       Remove unused local volumes
  rm          Remove one or more volumes
  update      Update a volume (cluster volumes only)

Run 'docker volume COMMAND --help' for more information on a command.

While the exit-code is no longer printed, it's still properly handled;

echo $?
125

- A picture of a cute animal (not mandatory but encouraged)

codecov-commenter commented 6 days ago

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 61.47%. Comparing base (5aae44b) to head (bca2090).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5231 +/- ## ========================================== - Coverage 61.48% 61.47% -0.02% ========================================== Files 298 298 Lines 20813 20815 +2 ========================================== - Hits 12797 12795 -2 - Misses 7104 7107 +3 - Partials 912 913 +1 ```
thaJeztah commented 6 days ago

I have some changes staged to look at actually providing an error-message for some of these, but I need to clean it up a bit 😅 - also have https://github.com/docker/cli/pull/5229#issuecomment-2209343234 as a follow-up.