From bbba087a83cf41ae2a7707fa1bfc50bf985fc8f4 Mon Sep 17 00:00:00 2001 From: Yoann La Cancellera Date: Tue, 12 Sep 2023 15:20:43 +0200 Subject: [PATCH] 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 --- src/go/pt-galera-log-explainer/internal.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/go/pt-galera-log-explainer/internal.go b/src/go/pt-galera-log-explainer/internal.go index d983bc9a..27fa8bf8 100644 --- a/src/go/pt-galera-log-explainer/internal.go +++ b/src/go/pt-galera-log-explainer/internal.go @@ -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 }