Browse Source

Remove more calls to log

Signed-off-by: Robert Lin <robertlin1@gmail.com>
Robert Lin 6 years ago
parent
commit
93c1f8b1a4
3 changed files with 16 additions and 9 deletions
  1. 3 2
      internal/plumbing/tree_diff.go
  2. 9 4
      leaves/couples.go
  3. 4 3
      leaves/file_history.go

+ 3 - 2
internal/plumbing/tree_diff.go

@@ -3,7 +3,6 @@ package plumbing
 import (
 import (
 	"fmt"
 	"fmt"
 	"io"
 	"io"
-	"log"
 	"path"
 	"path"
 	"regexp"
 	"regexp"
 	"strings"
 	"strings"
@@ -171,7 +170,9 @@ func (treediff *TreeDiff) Consume(deps map[string]interface{}) (map[string]inter
 		}
 		}
 	}
 	}
 	if !pass && treediff.previousCommit != plumbing.ZeroHash {
 	if !pass && treediff.previousCommit != plumbing.ZeroHash {
-		log.Panicf("%s > %s", treediff.previousCommit.String(), commit.Hash.String())
+		err := fmt.Errorf("%s > %s", treediff.previousCommit.String(), commit.Hash.String())
+		treediff.l.Error(err)
+		return nil, err
 	}
 	}
 	tree, err := commit.Tree()
 	tree, err := commit.Tree()
 	if err != nil {
 	if err != nil {

+ 9 - 4
leaves/couples.go

@@ -3,7 +3,6 @@ package leaves
 import (
 import (
 	"fmt"
 	"fmt"
 	"io"
 	"io"
-	"log"
 	"sort"
 	"sort"
 
 
 	"github.com/gogo/protobuf/proto"
 	"github.com/gogo/protobuf/proto"
@@ -218,14 +217,18 @@ func (couples *CouplesAnalysis) Finalize() interface{} {
 	for i, name := range filesSequence {
 	for i, name := range filesSequence {
 		file, err := couples.lastCommit.File(name)
 		file, err := couples.lastCommit.File(name)
 		if err != nil {
 		if err != nil {
-			log.Panicf("cannot find file %s in commit %s: %v",
+			err := fmt.Errorf("cannot find file %s in commit %s: %v",
 				name, couples.lastCommit.Hash.String(), err)
 				name, couples.lastCommit.Hash.String(), err)
+			couples.l.Error(err)
+			return err
 		}
 		}
 		blob := items.CachedBlob{Blob: file.Blob}
 		blob := items.CachedBlob{Blob: file.Blob}
 		err = blob.Cache()
 		err = blob.Cache()
 		if err != nil {
 		if err != nil {
-			log.Panicf("cannot read blob %s of file %s: %v",
+			err := fmt.Errorf("cannot read blob %s of file %s: %v",
 				blob.Hash.String(), name, err)
 				blob.Hash.String(), name, err)
+			couples.l.Error(err)
+			return err
 		}
 		}
 		filesLines[i], _ = blob.CountLines()
 		filesLines[i], _ = blob.CountLines()
 	}
 	}
@@ -307,8 +310,10 @@ func (couples *CouplesAnalysis) Deserialize(pbmessage []byte) (interface{}, erro
 		}
 		}
 	}
 	}
 	if len(message.FileCouples.Index) != len(message.FilesLines) {
 	if len(message.FileCouples.Index) != len(message.FilesLines) {
-		log.Panicf("Couples PB message integrity violation: file_couples (%d) != file_lines (%d)",
+		err := fmt.Errorf("Couples PB message integrity violation: file_couples (%d) != file_lines (%d)",
 			len(message.FileCouples.Index), len(message.FilesLines))
 			len(message.FileCouples.Index), len(message.FilesLines))
+		couples.l.Error(err)
+		return nil, err
 	}
 	}
 	for i, v := range message.FilesLines {
 	for i, v := range message.FilesLines {
 		result.FilesLines[i] = int(v)
 		result.FilesLines[i] = int(v)

+ 4 - 3
leaves/file_history.go

@@ -3,7 +3,6 @@ package leaves
 import (
 import (
 	"fmt"
 	"fmt"
 	"io"
 	"io"
-	"log"
 	"sort"
 	"sort"
 	"strings"
 	"strings"
 
 
@@ -164,7 +163,8 @@ func (history *FileHistoryAnalysis) Finalize() interface{} {
 	files := map[string]FileHistory{}
 	files := map[string]FileHistory{}
 	fileIter, err := history.lastCommit.Files()
 	fileIter, err := history.lastCommit.Files()
 	if err != nil {
 	if err != nil {
-		log.Panicf("Failed to iterate files of %s", history.lastCommit.Hash.String())
+		history.l.Errorf("Failed to iterate files of %s", history.lastCommit.Hash.String())
+		return err
 	}
 	}
 	err = fileIter.ForEach(func(file *object.File) error {
 	err = fileIter.ForEach(func(file *object.File) error {
 		if fh := history.files[file.Name]; fh != nil {
 		if fh := history.files[file.Name]; fh != nil {
@@ -173,7 +173,8 @@ func (history *FileHistoryAnalysis) Finalize() interface{} {
 		return nil
 		return nil
 	})
 	})
 	if err != nil {
 	if err != nil {
-		log.Panicf("Failed to iterate files of %s", history.lastCommit.Hash.String())
+		history.l.Errorf("Failed to iterate files of %s", history.lastCommit.Hash.String())
+		return err
 	}
 	}
 	return FileHistoryResult{Files: files}
 	return FileHistoryResult{Files: files}
 }
 }