Jira (PUP-2774) class can `require` itself without raising an error

9 views
Skip to first unread message

Henrik Lindberg (JIRA)

unread,
Jan 15, 2015, 4:07:12 PM1/15/15
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
 
Puppet / Improvement PUP-2774
class can `require` itself without raising an error
Change By: Henrik Lindberg
Scrum Team: Language
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Feb 2, 2016, 11:09:02 PM2/2/16
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Story Points: 1
This message was sent by Atlassian JIRA (v6.4.12#64027-sha1:e3691cc)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Feb 2, 2016, 11:09:02 PM2/2/16
to puppe...@googlegroups.com
Henrik Lindberg updated an issue

Now that we have a relationship validator in place this is very easy to do.

Henrik Lindberg (JIRA)

unread,
Sep 7, 2016, 6:12:26 PM9/7/16
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Team: Puppet Developer Support
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Mar 29, 2017, 5:39:03 PM3/29/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Fix Version/s: PUP 4.y
Fix Version/s: PUP 5.y

Russell Mull (JIRA)

unread,
May 16, 2017, 1:25:03 PM5/16/17
to puppe...@googlegroups.com

Russell Mull (JIRA)

unread,
May 16, 2017, 1:25:04 PM5/16/17
to puppe...@googlegroups.com
Russell Mull updated an issue
Change By: Russell Mull
Team: Puppet Developer Experience Agent

Russell Mull (JIRA)

unread,
May 16, 2017, 1:25:16 PM5/16/17
to puppe...@googlegroups.com

Moses Mendoza (JIRA)

unread,
May 18, 2017, 1:49:08 PM5/18/17
to puppe...@googlegroups.com

Maggie Dreyer (JIRA)

unread,
Oct 29, 2018, 7:22:02 PM10/29/18
to puppe...@googlegroups.com
Maggie Dreyer updated an issue
Change By: Maggie Dreyer
Team: Server Coremunity
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Josh Cooper (JIRA)

unread,
Jan 23, 2020, 2:34:04 PM1/23/20
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Dec 2, 2020, 6:41:03 PM12/2/20
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Labels: beginner help_wanted
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Josh Cooper (Jira)

unread,
Dec 2, 2020, 6:41:04 PM12/2/20
to puppe...@googlegroups.com
Josh Cooper commented on Improvement PUP-2774
 
Re: class can `require` itself without raising an error

The require function has been implemented using the 4x function API, so you'll want to look at https://github.com/puppetlabs/puppet/blob/96029b003cfbb5303426cbc110f350a0d4b6af06/lib/puppet/functions/require.rb#L71-L72.

Note resource is an instance of Puppet::Parser::Resource while ref is an instance of Puppet::Resource, and the former subclasses the latter. So you can compare the value objects directly to determine if they are equivalent.

Given the following manifest:

class a {
  require a
}
include a

We expect it to raise a parse error during compilation with file, line, etc info. One option is to:

1. Add a new issue constant to Puppet::Pops::Issues
2. If resource == ref then call

      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::YOUR_NEW_CONSTANT,
        {:operation => 'require'})

3. Add a test to spec/unit/functions/require_spec.rb to verify the excepted exception is raised when calling compile_to_catalog with the circular requirement.
4. Note this won't catch cycles among classes, e.g. A -> B -> A. Those will be caught later on.

Alternatively, you could add logic to https://github.com/puppetlabs/puppet/blob/96029b003cfbb5303426cbc110f350a0d4b6af06/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb#L25 to ensure the resource is not the same as the found object:

        if !found
          msg = _("Could not find resource '%{res}' in parameter '%{param}'") % { res: res, param: param.name.to_s }
          raise CatalogValidationError.new(msg, param.file, param.line)
        elsif found == resource
          msg = _("Resource '%{res}' cannot '%{param}' itself") % { res: res, param: param.name.to_s }
          raise CatalogValidationError.new(msg, param.file, param.line)
        end

Josh Cooper (Jira)

unread,
May 17, 2023, 2:15:01 PM5/17/23
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Team: Coremunity
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Josh Cooper (Jira)

unread,
May 17, 2023, 2:15:03 PM5/17/23
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages