GCSS-1167: handle import errors#48
Merged
Merged
Conversation
…d tests, update documentation and comments, and enhance code robustness
…d tests, update documentation and comments, and enhance code robustness
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.
Handle import errors better (repo not found)
Fixes G-Research/gr-oss#1167
Problem
When the importer was asked to import a repository that doesn't exist (or that the GitHub App can't see), it produced a noisy, confusing failure:
ImportRepowrapped it (failed to fetch repo: ...) and the command wrapped it again (failed to import repo: ...).There was also a latent nil-pointer panic: several API error paths dereferenced the HTTP response (
r.Status/r.StatusCode) without a nil check, so a transport-level error would crash with a stack trace instead of a message.Changes
pkg/github/github.goErrRepoNotFoundsentinel error.ImportReponow detects HTTP 404 (r != nil && r.StatusCode == http.StatusNotFound) and returns a single, clear message with guidance: "repository not found: "owner/repo" — check the spelling and that the GitHub App is installed and has access to it".r != nilguard on the rulesets403path (latent nil-deref) and switched its error to%wfor consistent wrapping.cmd/import.gofailed to import repo: %wwrap so the underlying message surfaces once.cmd/root.goSilenceUsage+SilenceErrorson the root command so runtime errors no longer trigger a usage dump; errors are printed once byExecute.GITHUB_ACTIONS=true), emit a::error::workflow-command annotation so the message shows up in the run summary, with proper escaping (%,\r,\n) per GitHub's spec.cmd/root_test.go(new)escapeAnnotationcovering each escape, a combined case, and that%is escaped before replacements are re-scanned.Justfileset -euo pipefailto theimport-reporecipe (a shebang recipe) so a failed import aborts instead of falling through tocpa stale/missing YAML.Before / After
Before
After
Plus, in GitHub Actions, a
::error::annotation on the run summary.