From b8e6bd8c9a3a72358ac033bc7f1f837ab6977b93 Mon Sep 17 00:00:00 2001 From: Laurence Jones Date: Fri, 29 Sep 2023 12:03:56 +0100 Subject: [PATCH] [Explain] s02 can cause panic if empty (#2486) * Add parsers length check as it can panic is enrich is empty * Lets get smarter and loop backwards to find last successful stage * Shorten code --------- Co-authored-by: Thibault "bui" Koechlin --- pkg/hubtest/parser_assert.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/hubtest/parser_assert.go b/pkg/hubtest/parser_assert.go index e27d7d878..d579a1be4 100644 --- a/pkg/hubtest/parser_assert.go +++ b/pkg/hubtest/parser_assert.go @@ -321,9 +321,14 @@ func LoadParserDump(filepath string) (*ParserResults, error) { stages = append(stages, k) } sort.Strings(stages) - /*the very last one is set to 'success' which is just a bool indicating if the line was successfully parsed*/ - lastStage := stages[len(stages)-2] - + var lastStage string + //Loop over stages to find last successful one with at least one parser + for i := len(stages) - 2; i >= 0; i-- { + if len(pdump[stages[i]]) != 0 { + lastStage = stages[i] + break + } + } parsers := make([]string, 0, len(pdump[lastStage])) for k := range pdump[lastStage] { parsers = append(parsers, k)