Gracefully handle "422: Reference does not exist" when deleting remote branch#1279
Merged
Gracefully handle "422: Reference does not exist" when deleting remote branch#1279
Conversation
So that it's possible to access it in mocked HTTP tests. Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
`fmt.Errorf` hides information and makes it hard to test for specific conditions in returned error. Return a structured error instead. Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
If a GitHub repo is configured to automatically delete branches after PR is merged, `gh pr merge` fails with error like: failed to delete remote branch: ... (422): 'Reference does not exist' Gracefully handle such case and don't report the error. Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
e1c7dd2 to
3afec6f
Compare
mislav
approved these changes
Jun 30, 2020
pborzenkov
commented
Jul 1, 2020
| Message string `json:"message"` | ||
| } | ||
| if err := json.Unmarshal(body, &parsedBody); err == nil { | ||
| httpError.Message = parsedBody.Message |
Contributor
Author
There was a problem hiding this comment.
You no longer pass body as error Message in case json.Unmarshal is unsuccessful. Is this intentional?
Contributor
There was a problem hiding this comment.
Yes, this is intentional. I remembered that the body of some 5xx responses might be a HTML document (caused by e.g. an outage) and we wouldn't want to show that as error message. For non-JSON responses, I'm fine if we just report HTTP {StatusCode} on stderr.
Contributor
Author
|
@mislav Thanks for the patch. Looks great aside from a very minor comment. |
vilmibm
approved these changes
Jul 1, 2020
This file contains hidden or 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
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.
Summary
This PR modifies
BrachDeleteRemoteto gracefully handle the case when remote branch has already been automaticallydeleted by GitHub.
Closes #1010