From bd42e80a551e36b4d9d1efb0c9687dd5d2be2a4d Mon Sep 17 00:00:00 2001 From: Omry Mendelovich <16597193+omryMen@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:31:11 +0300 Subject: [PATCH] add error return value to recover (#514) --- src/common/gitservice/git_service.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/gitservice/git_service.go b/src/common/gitservice/git_service.go index 6a3a61e6..f254247d 100644 --- a/src/common/gitservice/git_service.go +++ b/src/common/gitservice/git_service.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime/debug" "strings" "sync" @@ -15,6 +16,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/pkg/errors" ) type GitService struct { @@ -139,14 +141,15 @@ func (g *GitService) GetRepoName() string { return g.repoName } -func wrapGitBlame(selectedCommit *object.Commit, relativeFilePath string) (*git.BlameResult, error) { +func wrapGitBlame(selectedCommit *object.Commit, relativeFilePath string) (blame *git.BlameResult, err error) { // currently there's a bug inside go-git so in order to mitigate it we wrap it with recover defer func() { if r := recover(); r != nil { - fmt.Println("Recovered in f", r) + fmt.Println("Recovered in f", r, debug.Stack()) + err = errors.Errorf("unknown panic, %v", r) } }() - blame, err := git.Blame(selectedCommit, relativeFilePath) + blame, err = git.Blame(selectedCommit, relativeFilePath) if err != nil { return nil, fmt.Errorf("failed to get blame for latest commit of file %s because of error %s", relativeFilePath, err) }