services: Gracefully handle missing branches

When loading branches, if loading one fails, log an error, and ignore
the branch, rather than returning and causing an internal server error.

Ideally, we would only ignore the error if it was caused by a missing
branch, and do it silently, like the respective API endpoint does.
However, veryfing that at this place is not very practical, so for the
time being, ignore any and all branch loading errors.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-01-13 21:05:21 +01:00
parent 8266105f24
commit e552a8fd62
No known key found for this signature in database

View file

@ -95,7 +95,13 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git
for i := range dbBranches { for i := range dbBranches {
branch, err := loadOneBranch(ctx, repo, dbBranches[i], &rules, repoIDToRepo, repoIDToGitRepo) branch, err := loadOneBranch(ctx, repo, dbBranches[i], &rules, repoIDToRepo, repoIDToGitRepo)
if err != nil { if err != nil {
return nil, nil, 0, fmt.Errorf("loadOneBranch: %v", err) log.Error("loadOneBranch() on repo #%d, branch '%s' failed: %v", repo.ID, dbBranches[i].Name, err)
// TODO: Ideally, we would only do this if the branch doesn't exist
// anymore. That is not practical to check here currently, so we do
// this for all kinds of errors.
totalNumOfBranches--
continue
} }
branches = append(branches, branch) branches = append(branches, branch)