From 7425227c9a95d08bee808aafcb864aa61694e64c Mon Sep 17 00:00:00 2001 From: Claire <213631+nyobe@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:41:04 -0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Pat Gavlin --- ast/environment.go | 2 +- ast/expr.go | 7 ++++--- ast/testdata/parse/invalid-invocation/expected.json | 2 +- ast/testdata/parse/invalid-invocation2/expected.json | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ast/environment.go b/ast/environment.go index 89cfe785..9ee598ca 100644 --- a/ast/environment.go +++ b/ast/environment.go @@ -129,7 +129,7 @@ func (d *MapDecl[T]) parse(name string, node syntax.Node) syntax.Diagnostics { var v T vname := name + "." + kvp.Key.Value() if strings.HasPrefix(kvp.Key.Value(), "fn::") { - diags.Extend(syntax.NodeError(kvp.Key, "fn expression not allowed at the top level")) + diags.Extend(syntax.NodeError(kvp.Key, fmt.Sprintf("builtin function call %q not allowed at the top level", kvp.Key.Value()))) } vdiags := parseNode(vname, &v, kvp.Value) diags.Extend(vdiags...) diff --git a/ast/expr.go b/ast/expr.go index a1a9f61f..91b516c2 100644 --- a/ast/expr.go +++ b/ast/expr.go @@ -628,11 +628,12 @@ func tryParseFunction(node *syntax.ObjectNode) (Expr, syntax.Diagnostics, bool) var diags syntax.Diagnostics if node.Len() != 1 { for i := 0; i < node.Len(); i++ { - if strings.HasPrefix(node.Index(i).Key.Value(), "fn::") { - diags = append(diags, syntax.NodeError(node, "fn:: expression must be the only key within object")) - return nil, diags, false + if k := node.Index(i).Key.Value(); strings.HasPrefix(k, "fn::") { + diags = append(diags, syntax.NodeError(node, fmt.Sprintf("illegal call to builtin function: %q must be the only key within its containing object", k))) + } } + return nil, diags, false return nil, nil, false } diff --git a/ast/testdata/parse/invalid-invocation/expected.json b/ast/testdata/parse/invalid-invocation/expected.json index 2603b550..a46a3f07 100644 --- a/ast/testdata/parse/invalid-invocation/expected.json +++ b/ast/testdata/parse/invalid-invocation/expected.json @@ -53,7 +53,7 @@ "diags": [ { "Severity": 1, - "Summary": "fn:: expression must be the only key within object", + "Summary": "illegal call to builtin function: \"fn::rotate::provider\" must be the only key within its containing object", "Detail": "", "Subject": { "Filename": "invalid-invocation", diff --git a/ast/testdata/parse/invalid-invocation2/expected.json b/ast/testdata/parse/invalid-invocation2/expected.json index ddc3b2e9..fe24a84c 100644 --- a/ast/testdata/parse/invalid-invocation2/expected.json +++ b/ast/testdata/parse/invalid-invocation2/expected.json @@ -18,7 +18,7 @@ "diags": [ { "Severity": 1, - "Summary": "fn expression not allowed at the top level", + "Summary": "builtin function call \"fn::secret\" not allowed at the top level", "Detail": "", "Subject": { "Filename": "invalid-invocation2",