Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Pat Gavlin <[email protected]>
  • Loading branch information
nyobe and pgavlin committed Feb 19, 2025
1 parent 0b132e4 commit 7425227
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ast/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
7 changes: 4 additions & 3 deletions ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 637 in ast/expr.go

View workflow job for this annotation

GitHub Actions / lint / lint

unreachable: unreachable code (govet)
}

Expand Down
2 changes: 1 addition & 1 deletion ast/testdata/parse/invalid-invocation/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ast/testdata/parse/invalid-invocation2/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7425227

Please sign in to comment.