-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
cli: make cli.StatusError slightly prettier #5231
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thaJeztah
force-pushed
the
prettier_exit_status
branch
from
July 4, 2024 17:47
802de28
to
d42d73c
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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 |
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 #5229 (comment) as a follow-up. |
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: - If a status-message is provided; print just that (after all the status code is something that can be found from the shell, e.g. through `echo $?` in Bash). - If no status-message is provided: print a message more similar to Go's `exec.ExecError`, which uses `os.rocessState.String()` (see [1]). 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 [1]: https://github.com/golang/go/blob/82c14346d89ec0eeca114f9ca0e88516b2cda454/src/os/exec_posix.go#L107-L135 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah
force-pushed
the
prettier_exit_status
branch
from
July 4, 2024 20:10
d42d73c
to
bca2090
Compare
1 task
vvoland
approved these changes
Jul 5, 2024
This was referenced Jul 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
echo $?
in Bash).exec.ExecError
, which usesos.rocessState.String()
(see 1).Before this patch, an error without custom status would print:
After this patch:
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:
andCode:
, which resulted in some odd output.Before this patch:
With this patch, the error is shown as-is;
While the exit-code is no longer printed, it's still properly handled;
- A picture of a cute animal (not mandatory but encouraged)