Fix error on no repo found during search (#918)

This commit is contained in:
Shubham Agrawal 2023-12-16 03:35:27 +00:00 committed by Harness
parent 880f62a857
commit 35d8d29965
1 changed files with 10 additions and 3 deletions

View File

@ -23,6 +23,8 @@ import (
"github.com/harness/gitness/app/auth"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/rs/zerolog/log"
)
func (c *Controller) Search(
@ -54,8 +56,7 @@ func (c *Controller) Search(
}
if len(repoIDToPathMap) == 0 {
return types.SearchResult{}, fmt.Errorf(
"no repositories found for the given paths")
return types.SearchResult{}, usererror.NotFound("no repositories found")
}
repoIDs := make([]int64, 0, len(repoIDToPathMap))
@ -69,7 +70,13 @@ func (c *Controller) Search(
}
for idx, fileMatch := range result.FileMatches {
result.FileMatches[idx].RepoPath = repoIDToPathMap[fileMatch.RepoID]
repoPath, ok := repoIDToPathMap[fileMatch.RepoID]
if !ok {
log.Ctx(ctx).Warn().Msgf("repo path not found for repo ID %d, repo mapping: %v",
fileMatch.RepoID, repoIDToPathMap)
continue
}
result.FileMatches[idx].RepoPath = repoPath
}
return result, nil
}