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 // it will iterate on stdout pipe results
localTimeline, err := iterateOnGrepResults(path, regexes, stdout) localTimeline := iterateOnGrepResults(path, regexes, stdout)
if err != nil { if len(localTimeline) == 0 {
logger.Warn().Err(err).Msg("Failed to iterate on results") continue
} }
found = true found = true
logger.Debug().Str("path", path).Msg("Finished searching") 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 // 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 will iterate on every regexes in slice, and apply the handler for each
// it also filters out --since and --until rows // 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 ( var (
lt types.LocalTimeline lt types.LocalTimeline
@@ -178,7 +178,7 @@ func iterateOnGrepResults(path string, regexes types.RegexMap, grepStdout <-chan
continue continue
} }
if CLI.Until != nil && date != nil && CLI.Until.Before(date.Time) { if CLI.Until != nil && date != nil && CLI.Until.Before(date.Time) {
return lt, nil return lt
} }
recentEnough = true recentEnough = true
@@ -198,5 +198,5 @@ func iterateOnGrepResults(path string, regexes types.RegexMap, grepStdout <-chan
} }
} }
return lt, nil return lt
} }