Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error return value to recover #514

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/common/gitservice/git_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime/debug"
"strings"
"sync"

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
Loading