From d2b69e45ad9f0d65b8ff165111051690258f10b8 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Fri, 15 May 2020 16:00:57 -0400 Subject: [PATCH] Recovering from panic that can occur with make Signed-off-by: Matt Farina Signed-off-by: Matheus Hunsche --- pkg/strvals/parser.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/strvals/parser.go b/pkg/strvals/parser.go index db2fb60fe..c52f38ab1 100644 --- a/pkg/strvals/parser.go +++ b/pkg/strvals/parser.go @@ -231,7 +231,16 @@ func set(data map[string]interface{}, key string, val interface{}) { data[key] = val } -func setIndex(list []interface{}, index int, val interface{}) ([]interface{}, error) { +func setIndex(list []interface{}, index int, val interface{}) (l2 []interface{}, err error) { + // There are possible index values that are out of range on a target system + // causing a panic. This will catch the panic and return an error instead. + // The value of the index that causes a panic varies from system to system. + defer func() { + if r := recover(); r != nil { + err = fmt.Errorf("error processing index %d: %s", index, r) + } + }() + if index < 0 { return list, fmt.Errorf("negative %d index not allowed", index) }