Jira (PUP-10399) Error: wrong number of arguments (given 2, expected 1) Deferred function doesn't return file / line number

12 views
Skip to first unread message

Lucas Young (Jira)

unread,
Mar 27, 2020, 6:34:03 PM3/27/20
to puppe...@googlegroups.com
Lucas Young updated an issue
 
Puppet / Bug PUP-10399
Error: wrong number of arguments (given 2, expected 1) Deferred function doesn't return file / line number
Change By: Lucas Young
Summary: Error: wrong number of arguments (given 2, expected 1) Deferred fucntion function doesn't return file / line number
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Lucas Young (Jira)

unread,
Mar 27, 2020, 6:40:03 PM3/27/20
to puppe...@googlegroups.com
Lucas Young updated an issue
*Puppet Version: Puppet 6.10.2*
*Puppet Server Version: 2019.2.2*
*OS Name/Version: Ubuntu 16.04*

*+Actual Behavior:+* When setting up a deferred function if a difference number of arguments are passed into the dispatch declaration versus the actual method a Puppet run will generate the following error: "*Error: Failed to apply catalog: wrong number of arguments (given 2, expected 1)*"

The issue is that none of the file / line number information is returned as part of the error message above, offering no trace back to the origination of the error in the code base.

 

+*Code example:*+

 

 
{code:java}
dispatch :example do
 param 'String', :stuff
 optional_param 'String', :morestuff
end
def example(stuff)
 return stuff + 1
end
  {code}
 

When the same code is ran and it is not a Deferred function, a file / line number is included in that error message.  

 

*+Desired behavior:+* Generate an error message with a line / file indication: "Error: Failed tp apply catalog, wrong number of arguments (given 2, expected 1) (file: /home/test_user/Working/custom_function_repro/modules/test_module/manifests/init.pp, line: 2, column: 8)"

 

Henrik Lindberg (Jira)

unread,
Mar 28, 2020, 8:24:03 AM3/28/20
to puppe...@googlegroups.com
Henrik Lindberg commented on Bug PUP-10399
 
Re: Error: wrong number of arguments (given 2, expected 1) Deferred function doesn't return file / line number

Hm, that is bad and something I did not think about when implementing the support for Deferred. The problem here is that the file/line is not included in the serialization of the deferred value into the catalog. Thus when it is resolved (i.e. called) on the agent side it has lost all of the context in which it was created.

To fix this, when an instance of Deferred is created it needs to look on the puppet stack to get the caller's location. These two values must then be encoded in the Deferred instance, and then serialized. Then the logic that performs the call must make use of the file/line information which probably involves catch and re-raise-or-wrap depending on type of error being raised.

Since this affects the serialization a decision to include file/line must depend on what the agent accepts.

A compromise could be to show file/line for the resource attribute for which the deferred is resolved (IIRC those are available in the catalog). This may not be correct if the deferred is nested in some other structure, but perhaps better than nothing. Doing that would not require messing with the serialization protocol.

Lucas Young (Jira)

unread,
Mar 30, 2020, 10:28:03 AM3/30/20
to puppe...@googlegroups.com
Lucas Young updated an issue
Change By: Lucas Young
*Puppet Version: Puppet 6.10.2*
*Puppet Server Version: 2019.2.2*
*OS Name/Version: Ubuntu 16.04*

*+Actual Behavior:+* When setting up a deferred function if a difference different number of arguments are passed into the dispatch declaration versus the actual method a Puppet run will generate the following error: "*Error: Failed to apply catalog: wrong number of arguments (given 2, expected 1)*"


The issue is that none of the file / line number information is returned as part of the error message above, offering no trace back to the origination of the error in the code base.

 

+*Code example:*+
{code:java}dispatch :example do
 param 'String', :stuff
 optional_param 'String', :morestuff
end
def example(stuff)
 return stuff + 1
end
 {code}
When the same code is ran and it is not a Deferred function, a file / line number is included in that error message.  

 

*+Desired behavior:+* Generate an error message with a line / file indication: "Error: Failed tp apply catalog, wrong number of arguments (given 2, expected 1) (file: /home/test_user/Working/custom_function_repro/modules/test_module/manifests/init.pp, line: 2, column: 8)"

 

Rob Braden (Jira)

unread,
Mar 31, 2020, 2:17:04 PM3/31/20
to puppe...@googlegroups.com

Lucas Young (Jira)

unread,
Apr 1, 2020, 12:39:03 PM4/1/20
to puppe...@googlegroups.com
Lucas Young commented on Bug PUP-10399
 
Re: Error: wrong number of arguments (given 2, expected 1) Deferred function doesn't return file / line number

Rob Braden - it was reported by a customer of mine and I filed the ticket on their behalf. I don't know the significance off currently, so i'll have to check with them. I will talk to them about it tomorrow in my weekly call with him. From there, i'll either update the ticket or have him provide an update with additional context / impact from their perspective.

Lucas Young (Jira)

unread,
Apr 1, 2020, 12:39:03 PM4/1/20
to puppe...@googlegroups.com
Lucas Young updated an issue
 
Change By: Lucas Young
Comment: [~bradejr] - it was reported by a customer of mine and I filed the ticket on their behalf. I don't know the significance off currently, so i'll have to check with them. I will talk to them about it tomorrow in my weekly call with him. From there, i'll either update the ticket or have him provide an update with additional context / impact from their perspective.

Josh Cooper (Jira)

unread,
Jun 7, 2022, 12:14:05 PM6/7/22
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Component/s: Deferred
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages