From e552a8fd629b11503569f605c824c1c0b01eeab2 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 13 Jan 2024 21:05:21 +0100 Subject: [PATCH] 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 --- services/repository/branch.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/repository/branch.go b/services/repository/branch.go index 0313566ed8..70ff8db449 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -95,7 +95,13 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git for i := range dbBranches { branch, err := loadOneBranch(ctx, repo, dbBranches[i], &rules, repoIDToRepo, repoIDToGitRepo) 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)