summaryrefslogtreecommitdiff
path: root/cmd/kdev/record_extractor.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-03-10 13:20:17 +0100
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-03-10 13:20:17 +0100
commitd6ddf7fa61b9e42ad63fee0cb8b67bf0a23fc4f0 (patch)
tree3b2ecf1acfc57c1cff10008168729f27cd03af55 /cmd/kdev/record_extractor.go
parent263fa3d9d6263e3cbcd7df4599460cc0c2abb9ee (diff)
fix(git): No crash when git fails
Diffstat (limited to 'cmd/kdev/record_extractor.go')
-rw-r--r--cmd/kdev/record_extractor.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/cmd/kdev/record_extractor.go b/cmd/kdev/record_extractor.go
index 5781077..a44d6c6 100644
--- a/cmd/kdev/record_extractor.go
+++ b/cmd/kdev/record_extractor.go
@@ -15,7 +15,7 @@ import (
)
type RecordExtractor interface {
- Extract(keyword string, path string, line int) Record
+ Extract(keyword string, path string, line int) (Record, error)
}
type StatRecordExtractor struct {
@@ -31,13 +31,13 @@ func NewStatRecordExtractor(absolutePath string) *StatRecordExtractor {
}
}
-func (re *StatRecordExtractor) Extract(keyword string, path string, line int) Record {
+func (re *StatRecordExtractor) Extract(keyword string, path string, line int) (Record, error) {
return Record{
keyword: keyword,
path: path,
line: line,
date: re.fileInfo.ModTime(),
- }
+ }, nil
}
type GoGitRecordExtractor struct {
@@ -54,24 +54,22 @@ func NewGoGitRecordExtractor(head *object.Commit, path string) *GoGitRecordExtra
}
}
-func (re *GoGitRecordExtractor) Extract(keyword string, path string, line int) Record {
+func (re *GoGitRecordExtractor) Extract(keyword string, path string, line int) (Record, error) {
record := Record{
keyword: keyword,
path: path,
line: line,
}
- if re != nil {
- record.date = re.blame.Lines[line-1].Date
- }
+ record.date = re.blame.Lines[line-1].Date
- return record
+ return record, nil
}
type GitRecordExtractor struct {
repoPath string
}
-func (re *GitRecordExtractor) Extract(keyword string, path string, line int) Record {
+func (re *GitRecordExtractor) Extract(keyword string, path string, line int) (Record, error) {
record := Record{
keyword: keyword,
path: path,
@@ -83,7 +81,7 @@ func (re *GitRecordExtractor) Extract(keyword string, path string, line int) Rec
output, err := cmd.Output()
if err != nil {
- panic(kcore.Wrap(err, fmt.Sprintf("Error running: git %s", strings.Join(gitArgs, " "))))
+ return record, kcore.Wrap(err, fmt.Sprintf("Error running: git %s", strings.Join(gitArgs, " ")))
}
for _, blameLine := range strings.Split(string(output), "\n") {
@@ -91,9 +89,10 @@ func (re *GitRecordExtractor) Extract(keyword string, path string, line int) Rec
timestamp, err := strconv.ParseInt(strings.TrimPrefix(blameLine, "author-time "), 10, 64)
kcore.Expect(err, "Error parsing timestamp")
record.date = time.Unix(timestamp, 0)
- return record
+ return record, nil
}
}
kcore.Assert(false, "No date found in git blame output")
- return Record{}
+
+ return Record{}, nil
}