Skip to content

Commit

Permalink
Don't crash if there's no package list client (#3034)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhrozek authored and dmjb committed Apr 11, 2024
1 parent ba97323 commit 9fd899f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/providers/github/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ var (
ErrNotFound = errors.New("not found")
// ErrBranchNotFound denotes if the branch was not found
ErrBranchNotFound = errors.New("branch not found")
// ErrNoPackageListingClient denotes if there is no package listing client available
ErrNoPackageListingClient = errors.New("no package listing client available")
)

// GitHub is the struct that contains the shared GitHub client operations
Expand Down Expand Up @@ -171,6 +173,11 @@ func (c *GitHub) ListPackagesByRepository(
// create a slice to hold the containers
var allContainers []*github.Package

if c.packageListingClient == nil {
zerolog.Ctx(ctx).Error().Msg("No client available for listing packages")
return allContainers, ErrNoPackageListingClient
}

type listPackagesRespWrapper struct {
artifacts []*github.Package
resp *github.Response
Expand Down Expand Up @@ -205,7 +212,7 @@ func (c *GitHub) ListPackagesByRepository(
for {
result, err := performWithRetry(ctx, op)
if err != nil {
if result.resp.StatusCode == http.StatusNotFound {
if result.resp != nil && result.resp.StatusCode == http.StatusNotFound {
return allContainers, fmt.Errorf("packages not found for repository %d: %w", repositoryId, ErrNotFound)
}

Expand Down
8 changes: 8 additions & 0 deletions internal/reconcilers/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ThreeDotsLabs/watermill/message"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"google.golang.org/protobuf/types/known/timestamppb"

Expand Down Expand Up @@ -137,6 +138,13 @@ func (r *Reconciler) handleArtifactsReconcilerEvent(ctx context.Context, evt *Re
// we do not return error since it's a valid use case for a repository to not have artifacts
log.Printf("error retrieving artifacts for RepoID %d: %v", repository.RepoID, err)
return nil
} else if errors.Is(err, github.ErrNoPackageListingClient) {
// not a hard error, just misconfiguration or the user doesn't want to put a token
// into the provider config
zerolog.Ctx(ctx).Info().
Str("provider", prov.ID.String()).
Msg("No package listing client available for provider")
return nil
}
return err
}
Expand Down

0 comments on commit 9fd899f

Please sign in to comment.