Improve error messages on CLI HTTP request errors #5519
Merged
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.
Overview
What does this change accomplish and why?
This PR improves error messages when an HTTP request returns an unexpected status code, typically an error code.
Previously, the error message dumped the full request and response data without a friendly summary or message:
This PR surfaces the HTTP response status code and body message so a user can understand what went wrong and perhaps how to fix it at a glance:
If relevant, which Github issues does it close?
I didn't find an existing issue for this with a brief search.
Implementation notes
Updates
Unison.CommandLine.OutputMessages
to summarize HTTP response error info when aServant.FailureResponse
is encountered.Interesting/controversial decisions
I reused the verbiage from code paths that handle
Share.UnexpectedResponse
inOutputMessages
.Initially, the use of "we" was kept from the original message used by
Share.UnexpectedResponse
.As suggested, the message was changed to use
I
instead ofWe
for consistency with other UCM CLI messages.Test coverage
Have you included tests (which could be a transcript) for this change, or is it somehow covered by existing tests?
New automated tests are not included in this PR and error case tests for
pull
or similar CLI commands do not seem to be included in existing transcript tests.I manually tested the following commands which are affected by this change:
pull
lib.install
A transcript test could be useful to protect against regression, but it requires integrating with an API server and may not be idempotent. When I tried adding a transcript test using the
:error
directive, the automatic error message also included a lot of ANSI escape code noise, making it difficult to interpret the test.There may be other common commands that can hit a
Servant.FailureResponse
that should be tested.Loose ends