From b429fbd1b00ccdf8f183f41fbd1f06cfe6ad0cf1 Mon Sep 17 00:00:00 2001 From: kayrus Date: Tue, 26 Nov 2019 11:24:18 +0100 Subject: [PATCH] Make a bool conversion error more verbose --- cty/convert/conversion_primitive.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cty/convert/conversion_primitive.go b/cty/convert/conversion_primitive.go index e0dbf491..0d6fae96 100644 --- a/cty/convert/conversion_primitive.go +++ b/cty/convert/conversion_primitive.go @@ -1,6 +1,8 @@ package convert import ( + "strings" + "github.com/zclconf/go-cty/cty" ) @@ -41,7 +43,14 @@ var primitiveConversionsUnsafe = map[cty.Type]map[cty.Type]conversion{ case "false", "0": return cty.False, nil default: - return cty.NilVal, path.NewErrorf("a bool is required") + switch strings.ToLower(val.AsString()) { + case "true": + return cty.NilVal, path.NewErrorf("a bool is required; to convert from string, use lowercase \"true\"") + case "false": + return cty.NilVal, path.NewErrorf("a bool is required; to convert from string, use lowercase \"false\"") + default: + return cty.NilVal, path.NewErrorf("a bool is required") + } } }, },