-
Notifications
You must be signed in to change notification settings - Fork 6.9k
fix error for ErrReleaseNotFound when fetching ref #11451
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
Conversation
Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an error handling issue in the FetchRefSHA
function where JSON decoding errors were not being properly mapped to the expected ErrReleaseNotFound
error type.
- Replaces generic JSON decoding error with specific
ErrReleaseNotFound
error - Adds clarifying comment about release not being found
the lint error can ignore. not related to the change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @ejahnGithub! 🙏
But I believe the change may have unwanted side effects for other release
commands.
@@ -164,7 +164,8 @@ func FetchRefSHA(ctx context.Context, httpClient *http.Client, repo ghrepo.Inter | |||
} `json:"object"` | |||
} | |||
if err := json.NewDecoder(resp.Body).Decode(&ref); err != nil { | |||
return "", err | |||
// release not found | |||
return "", ErrReleaseNotFound |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change also affects other release
subcmds. I agree with CCR in that this error can have other reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When fetching the ref SHA of a tag, a partial semver match returns a 200 response with an empty body, which causes the JSON decode to fail.
For example, if the tag is v1.0.0, only refs/tags/v1.0.0 will work — v1 or v1.0 will return 200 with empty body.
This behavior aligns with other gh release commands, which also require the exact tag name, otherwise would return release not found. Partial semver versions won’t work — only the full, exact tag is accepted.
This pull request improves error handling in the FetchRefSHA function to provide a clearer message when a release is not found.
Previously, if the CLI attempted to fetch
gh release verify tag
and the tag’s semver did not exactly match, it would return a low-level JSON parsing error:With this fix, the CLI now returns: