Fix: crash when timeline is empty

It was due to a silly regression when reformatting the main.go
The function iterating was doing too many things, and returning an error
when nothing was found, and a "continue" was done on the main
"timelineFromPaths" loop
It is now a simple foreach loop that does not return error so we have to
check if the localtimeline slice is empty
This commit is contained in:
Yoann La Cancellera
2023-09-12 15:20:43 +02:00
parent 7f8071ce3f
commit bbba087a83

View File

@@ -44,9 +44,9 @@ func timelineFromPaths(paths []string, regexes types.RegexMap) (types.Timeline,
}()
// it will iterate on stdout pipe results
localTimeline, err := iterateOnGrepResults(path, regexes, stdout)
if err != nil {
logger.Warn().Err(err).Msg("Failed to iterate on results")
localTimeline := iterateOnGrepResults(path, regexes, stdout)
if len(localTimeline) == 0 {
continue
}
found = true
logger.Debug().Str("path", path).Msg("Finished searching")
@@ -153,7 +153,7 @@ func sanitizeLine(s string) string {
// iterateOnGrepResults will take line by line each logs that matched regex
// it will iterate on every regexes in slice, and apply the handler for each
// it also filters out --since and --until rows
func iterateOnGrepResults(path string, regexes types.RegexMap, grepStdout <-chan string) (types.LocalTimeline, error) {
func iterateOnGrepResults(path string, regexes types.RegexMap, grepStdout <-chan string) types.LocalTimeline {
var (
lt types.LocalTimeline
@@ -178,7 +178,7 @@ func iterateOnGrepResults(path string, regexes types.RegexMap, grepStdout <-chan
continue
}
if CLI.Until != nil && date != nil && CLI.Until.Before(date.Time) {
return lt, nil
return lt
}
recentEnough = true
@@ -198,5 +198,5 @@ func iterateOnGrepResults(path string, regexes types.RegexMap, grepStdout <-chan
}
}
return lt, nil
return lt
}