docker / cli

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

cli/command/container: remove reportError, and put StatusError to use #5236

Open thaJeztah opened 5 days ago

thaJeztah commented 5 days ago

The reportError utility was present because cli.StatusError would print the error decorated with Status: <error-message>, Code: <exit-code>. That was not desirable in many cases as it would mess-up the output. To prevent this, the CLI had code to check for an empty Status (error message) in which case the error would be "ignored" (and only used for the exit-status), and the reportError utility would be used to manually print a custom error message before returning the error.

Now that bca209006153d3e025cb3d31c3cd55eb2aec0c4f fixed the output format of cli.StatusError, and 3dd6fc365d853e21f0e11f9e6ab62c4f8ae438e7 and 350a0b68a9584ec9ae712b6eca906c1018ba6dac no longer discard these error, we can get rid of this utility, and just set the error-message for the status-error.

This patch:

Behavior is mostly unmodified, with the exception of some slight reformatting of the errors:

Before this patch:

$ docker run --pull=invalid-option alpine
docker: invalid pull option: 'invalid-option': must be one of "always", "missing" or "never".
See 'docker run --help'.
$ echo $?
125

$ docker run --rm alpine nosuchcommand
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "nosuchcommand": executable file not found in $PATH: unknown.
$ echo $?
127

With this patch:

$ docker run --pull=invalid-option alpine
docker: invalid pull option: 'invalid-option': must be one of "always", "missing" or "never"

Run 'docker run --help' for more information
$ echo $?
125

$ docker run --rm alpine nosuchcommand
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "nosuchcommand": executable file not found in $PATH: unknown.

Run 'docker run --help' for more information
$ echo $?
127
codecov-commenter commented 5 days ago

Codecov Report

Attention: Patch coverage is 40.00000% with 21 lines in your changes missing coverage. Please review.

Project coverage is 61.46%. Comparing base (61c6ff2) to head (882d070).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5236 +/- ## ========================================== - Coverage 61.49% 61.46% -0.03% ========================================== Files 298 298 Lines 20811 20814 +3 ========================================== - Hits 12797 12794 -3 - Misses 7102 7109 +7 + Partials 912 911 -1 ```
thaJeztah commented 5 days ago

@laurazard first round of cleanup after the other one(s) 😄