Skip to content

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

Merged
merged 2 commits into from
Aug 8, 2025

Conversation

ejahnGithub
Copy link
Contributor

@ejahnGithub ejahnGithub commented Aug 5, 2025

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:

json: cannot unmarshal array into Go value of type struct { Object struct { SHA string "json:\"sha\"" } "json:\"object\"" }

With this fix, the CLI now returns:

no release found

@ejahnGithub ejahnGithub marked this pull request as ready for review August 8, 2025 17:29
@Copilot Copilot AI review requested due to automatic review settings August 8, 2025 17:29
@ejahnGithub ejahnGithub requested a review from a team as a code owner August 8, 2025 17:29
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Aug 8, 2025
@cliAutomation
Copy link
Collaborator

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.

Copy link
Contributor

@Copilot Copilot AI left a 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

@ejahnGithub
Copy link
Contributor Author

the lint error can ignore. not related to the change

@ejahnGithub ejahnGithub merged commit dd26fba into trunk Aug 8, 2025
14 of 16 checks passed
@ejahnGithub ejahnGithub deleted the eugene/fetch-ref-handle-ReleaseNotFound branch August 8, 2025 18:52
Copy link
Member

@babakks babakks left a 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
Copy link
Member

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external pull request originating outside of the CLI core team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants