From 00a96c099c1c448d9453a0c3c5c3415e18513413 Mon Sep 17 00:00:00 2001 From: Owen Rumney Date: Fri, 21 Jan 2022 08:25:41 +0000 Subject: [PATCH] add more detail to patch errors --- commenter/commenter.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commenter/commenter.go b/commenter/commenter.go index 91603ac..bbd90de 100644 --- a/commenter/commenter.go +++ b/commenter/commenter.go @@ -193,17 +193,21 @@ func buildComment(file, comment string, line int, info commitFileInfo) *github.P } func getCommitInfo(file *github.CommitFile) (*commitFileInfo, error) { + patch := file.GetPatch() + if patch == "" { + return nil, nil + } groups := patchRegex.FindAllStringSubmatch(file.GetPatch(), -1) if len(groups) < 1 { - return nil, errors.New("the patch details could not be resolved") + return nil, fmt.Errorf("the patch details for [%s] could not be resolved", *file.Filename) } hunkStart, _ := strconv.Atoi(groups[0][1]) hunkEnd, _ := strconv.Atoi(groups[0][2]) shaGroups := commitRefRegex.FindAllStringSubmatch(file.GetContentsURL(), -1) if len(shaGroups) < 1 { - return nil, errors.New("the sha details could not be resolved") + return nil, fmt.Errorf("the sha details for [%s] could not be resolved", *file.Filename) } sha := shaGroups[0][1]