Jira (PUP-10782) Could not parse for environment ...: Syntax error at '=>' ...

8 views
Skip to first unread message

Exidex (Jira)

unread,
Nov 12, 2020, 9:13:03 AM11/12/20
to puppe...@googlegroups.com
Exidex created an issue
 
Puppet / Bug PUP-10782
Could not parse for environment ...: Syntax error at '=>' ...
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2020/11/12 6:12 AM
Priority: Normal Normal
Reporter: Exidex

Puppet Version: 6.18.0
Puppet Server Version: 6.13.0
OS Name/Version: Ubuntu 18.04

function test::valid() >> Data {
  {
    "test" => ""
  }
}
 
function test::invalid() >> Data {
  $test_one = [
  ]
 
  {
    "test" => $test_one
  }
}
function test::valid2() >> Data {
  $test_one = [
  ]
 
  $test = {
    "test" => $test_one
  }
  $test
}

Desired Behavior:

Second function example expected to parse correctly or give better error message

Actual Behavior:

Second function in code snippet fails when parsing.

Shows error:

Error: Could not parse for environment ...: Syntax error at '=>' (file: ...

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Henrik Lindberg (Jira)

unread,
Nov 12, 2020, 12:06:03 PM11/12/20
to puppe...@googlegroups.com
Henrik Lindberg commented on Bug PUP-10782
 
Re: Could not parse for environment ...: Syntax error at '=>' ...

Well, that is the point at which the syntax error occurs. There isn't really much that can be done about that.
The second function is just wrong - it cannot be parsed - the first expression appears to set a variable to an empty array, but it actually continues with the brace enclosed part since an expression followed by a block may be one of the resource type expressions.

In most cases when wanting to return a literal hash, the preceding line must be terminated with semicolon ;, or use an explicit return.

function test::invalid() >> Data {
  $test_one = [
  ];
  {
    "test" => $test_one
  }
}

function test::invalid() >> Data {
  $test_one = [
  ]
 
  return( {
    "test" => $test_one
  })
}

The parsing technology used by puppet does not have enough lookahead to be able to "do the right thing" and this is therefore very difficult to do anything about.

Henrik Lindberg (Jira)

unread,
Nov 12, 2020, 12:06:03 PM11/12/20
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Nov 12, 2020, 1:50:03 PM11/12/20
to puppe...@googlegroups.com
Josh Cooper commented on Improvement PUP-10782
 
Re: Could not parse for environment ...: Syntax error at '=>' ...

Based on Henrik Lindberg comment, I'm going to close this as won't/can't do.

Jesse Hathaway (Jira)

unread,
Apr 7, 2022, 3:48:03 PM4/7/22
to puppe...@googlegroups.com

Just ran into this today, is it documented anywhere, I couldn't find it on the hashes doc, https://puppet.com/docs/puppet/7/lang_data_hash.html

fails without semicolon:

$c = 'bubbles'
{'butter' => $c}.each |$a, $b| { notice($a,$b) }

succeeds with semicolon:

$c = 'bubbles'
;{'butter' => $c}.each |$a, $b| { notice($a,$b) }

It would be nice to understand when a semicolon is needed before an anonymous hash

This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages