From 48b573e835533075e4b650e212f62f20009750a4 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 1 Dec 2022 00:52:05 +0100 Subject: [PATCH] bake: fix panic for unsupported hcl variable type Signed-off-by: CrazyMax --- bake/hcl_test.go | 12 ++++++++++++ bake/hclparser/hclparser.go | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bake/hcl_test.go b/bake/hcl_test.go index 7294171b..903a5b7b 100644 --- a/bake/hcl_test.go +++ b/bake/hcl_test.go @@ -782,3 +782,15 @@ func TestFunctionNoResult(t *testing.T) { _, err := ParseFile(dt, "docker-bake.hcl") require.Error(t, err) } + +func TestVarUnsupportedType(t *testing.T) { + dt := []byte(` + variable "FOO" { + default = [] + } + target "default" {}`) + + t.Setenv("FOO", "bar") + _, err := ParseFile(dt, "docker-bake.hcl") + require.Error(t, err) +} diff --git a/bake/hclparser/hclparser.go b/bake/hclparser/hclparser.go index 3fdfb0f8..bfd3652f 100644 --- a/bake/hclparser/hclparser.go +++ b/bake/hclparser/hclparser.go @@ -241,7 +241,7 @@ func (p *parser) resolveValue(name string) (err error) { return nil } else { // TODO: support lists with csv values - return errors.Errorf("unsupported type %s for variable %s", v.Type(), name) + return errors.Errorf("unsupported type %s for variable %s", vv.Type().FriendlyName(), name) } } v = &vv