From 9dfa64b22180a87fb65c93b652fa76d0ff582242 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:49:37 +0200 Subject: [PATCH 1/2] avoid panic in stringOrList DecodeMapstructure func if string type assertion isn't ok, return an error instead of trigger a panic Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- types/stringOrList.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/types/stringOrList.go b/types/stringOrList.go index 059043fb..a6720df0 100644 --- a/types/stringOrList.go +++ b/types/stringOrList.go @@ -28,7 +28,11 @@ func (l *StringList) DecodeMapstructure(value interface{}) error { case []interface{}: list := make([]string, len(v)) for i, e := range v { - list[i] = e.(string) + val, ok := e.(string) + if !ok { + return fmt.Errorf("invalid type %T for string list", value) + } + list[i] = val } *l = list default: From 0aa24b289becf1ff8cba7057d9e25f5e86d0f036 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:51:23 +0200 Subject: [PATCH 2/2] be sure path property exists in env_file attribut definition Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- override/uncity.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/override/uncity.go b/override/uncity.go index 057b2f28..7819015e 100644 --- a/override/uncity.go +++ b/override/uncity.go @@ -198,12 +198,15 @@ func portIndexer(y any, p tree.Path) (string, error) { return "", nil } -func envFileIndexer(y any, _ tree.Path) (string, error) { +func envFileIndexer(y any, p tree.Path) (string, error) { switch value := y.(type) { case string: return value, nil case map[string]any: - return value["path"].(string), nil + if pathValue, ok := value["path"]; ok { + return pathValue.(string), nil + } + return "", fmt.Errorf("environment path attribut %s is missing", p) } return "", nil }