From 35d8d29965d22209224d28d0e4ac913fef9f59d5 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Sat, 16 Dec 2023 03:35:27 +0000 Subject: [PATCH] Fix error on no repo found during search (#918) --- app/api/controller/keywordsearch/search.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/api/controller/keywordsearch/search.go b/app/api/controller/keywordsearch/search.go index 23c206033..48da66220 100644 --- a/app/api/controller/keywordsearch/search.go +++ b/app/api/controller/keywordsearch/search.go @@ -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 }