Skip to content

Commit

Permalink
Prevent stopping repo-sync if querying Bitbucket projectKeys returns …
Browse files Browse the repository at this point in the history
…"fatal" error (#40582)

* Prevent stopping sync if a querying for repos in Bitbucket project key returns a 'fatal' error
  • Loading branch information
varsanojidan committed Aug 22, 2022
1 parent 898aa34 commit bdb0a0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion internal/repos/bitbucketserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ func (s *BitbucketServerSource) listAllRepos(ctx context.Context, results chan S

repos, err := s.client.ProjectRepos(ctx, q)
if err != nil {
ch <- batch{err: errors.Wrapf(err, "bitbucketserver.projectKeys: query=%q", q)}
// Getting a "fatal" error for a single project key is not a strong
// enough reason to stop syncing, instead wrap this error as a warning
// so that the sync can continue.
ch <- batch{err: errors.NewWarningError(errors.Wrapf(err, "bitbucketserver.projectKeys: query=%q", q))}
return
}

Expand Down
7 changes: 6 additions & 1 deletion internal/repos/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ func (s *Syncer) SyncExternalService(
seen := make(map[api.RepoID]struct{})
var errs error
fatal := func(err error) bool {
// If the error is just a warning, then it is not fatal.
if errors.IsWarning(err) && !errcode.IsAccountSuspended(err) {
return false
}

return errcode.IsUnauthorized(err) ||
errcode.IsForbidden(err) ||
errcode.IsAccountSuspended(err)
Expand All @@ -602,9 +607,9 @@ func (s *Syncer) SyncExternalService(
logger.Error("error from codehost", log.Int("seen", len(seen)), log.Error(err))

errs = errors.Append(errs, errors.Wrapf(err, "fetching from code host %s", svc.DisplayName))

if fatal(err) {
// Delete all external service repos of this external service
logger.Error("stopping external service sync due to fatal error from codehost", log.Error(err))
seen = map[api.RepoID]struct{}{}
break
}
Expand Down

0 comments on commit bdb0a0d

Please sign in to comment.