From 239fc1e24f3023a278578c788e4560606cc46778 Mon Sep 17 00:00:00 2001 From: "Thierno IB. BARRY" Date: Sun, 17 May 2020 14:18:53 +0200 Subject: [PATCH] don't dump template string in errors --- lang/funcs/string.go | 2 +- lang/funcs/string_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lang/funcs/string.go b/lang/funcs/string.go index e63283537e65..0bd5853895d8 100644 --- a/lang/funcs/string.go +++ b/lang/funcs/string.go @@ -78,7 +78,7 @@ func MakeTemplateFunc(funcsCb func() map[string]function.Function) function.Func } loadTmpl := func(fn string) (hcl.Expression, error) { - expr, diags := hclsyntax.ParseTemplate([]byte(fn), fn, hcl.Pos{Line: 1, Column: 1}) + expr, diags := hclsyntax.ParseTemplate([]byte(fn), params[0].Name, hcl.Pos{Line: 1, Column: 1}) if diags.HasErrors() { return nil, diags } diff --git a/lang/funcs/string_test.go b/lang/funcs/string_test.go index e60ebfaa2a51..efdac48b78ae 100644 --- a/lang/funcs/string_test.go +++ b/lang/funcs/string_test.go @@ -85,7 +85,7 @@ func TestTemplate(t *testing.T) { cty.StringVal("Hello, ${name}!"), cty.EmptyObjectVal, cty.NilVal, - `vars map does not contain key "name", referenced at Hello, ${name}!:1,10-14`, + `vars map does not contain key "name", referenced at str:1,10-14`, }, { cty.StringVal(""), @@ -135,7 +135,7 @@ func TestTemplate(t *testing.T) { cty.StringVal("Hello, ${template(\"\",{})}!"), cty.MapValEmpty(cty.String), cty.NilVal, - `Hello, ${template("",{})}!:1,10-19: Error in function call; Call to function "template" failed: cannot recursively call template from inside template call.`, + `str:1,10-19: Error in function call; Call to function "template" failed: cannot recursively call template from inside template call.`, }, { cty.StringVal("%{ for x in list ~}\n- ${x}\n%{ endfor ~}"), @@ -155,7 +155,7 @@ func TestTemplate(t *testing.T) { "list": cty.True, }), cty.NilVal, - "%{ for x in list ~}\n- ${x}\n%{ endfor ~}:1,13-17: Iteration over non-iterable value; A value of type bool cannot be used as the collection in a 'for' expression.", + `str:1,13-17: Iteration over non-iterable value; A value of type bool cannot be used as the collection in a 'for' expression.`, }, { cty.StringVal("${val}"),