Poise cookbook failing with compilation error - macos

I am getting compile error on poise cookbook . i started to get this error starting yesterday. was there any change done recently ? or do we have fix for this ??
=============================================================================== Recipe Compile Error in
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/libraries/default.rb
ArgumentError
------------- wrong number of arguments (given 2, expected 1)
Cookbook Trace: (most recent call first)
---------------------------------------- /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise/files/halite_gem/poise/helpers/option_collector.rb:98:in
option_collector_attribute' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise/files/halite_gem/poise/helpers/option_collector.rb:83:in attribute'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise/files/halite_gem/poise/helpers/template_content.rb:143:in
attribute' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:67:in class:Resource'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:39:in
<module:PoiseArchive>' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:28:in module:Resources'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:25:in
<module:PoiseArchive>' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:24:in <top (required)>'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources.rb:17:in
<top (required)>' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/cheftie.rb:17:in <top (required)>'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/libraries/default.rb:19:in
`<top (required)>'
Relevant File Content:
---------------------- /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise/files/halite_gem/poise/helpers/option_collector.rb:
91: # #param name [String, Symbol] Name of the attribute to
define. 92: # #param default [Hash] Default value for the
options. 93: # #param parser [Proc, Symbol] Optional parser
method. If a symbol it is 94: # called as a method on
self. Takes a non-hash value and returns a 95: # hash of
its parsed representation. 96: # #param forced_keys
[Array, Set] Method names that will be forced 97:
to be options rather than calls to the parent resource. 98>> def option_collector_attribute(name, default: {}, parser: nil,
forced_keys: Set.new) 99: raise Poise::Error.new("Parser
must be a Proc or Symbol: #{parser.inspect}") if parser &&
!(parser.is_a?(Proc) || parser.is_a?(Symbol)) 100: # Cast
to a set at definition time. 101: forced_keys =
Set.new(forced_keys) unless forced_keys.is_a?(Set) 102: #
Never allow name to be called accidentally since it does really wonky
things. 103: forced_keys.add(:name) 104: #
Unlike LWRPBase.attribute, I don't care about Ruby 1.8. Worlds tiniest
violin. 105: define_method(name.to_sym) do |arg=nil,
&block| 106: iv_sym = :"##{name}" 107:
System Info:
------------ chef_version=17.0.242 platform=mac_os_x platform_version=10.15.4 ruby=ruby 3.0.1p64 (2021-04-05 revision
0fb782ee38) [x86_64-darwin18] program_name=/usr/local/bin//chef-client
executable=/opt/chef/bin/chef-client

The poise-archive cookbook has been deprecated and archived for a long time:
https://github.com/poise/poise-archive
On Chef Infra 17.0 those poise_archive resources should be converted to archive_file resources which do not require an external cookbook:
https://docs.chef.io/resources/archive_file
The poise cookbooks being broken is not a bug which will be fixed.

Related

Wrong number arguments error when using unpacked keyword args along with send

I noticed that attempting to use the send method while passing in unpacked keyword args as a variable led to some unexpected behavior.
First the setup:
class SomeClass
def some_method
true
end
end
kwargs = {}
c = SomeClass.new
c.some_method
=> true
c.some_method(**kwargs)
=> true
c.send(:some_method, **{})
=> true
All of the above works as expected. However, if I attempt to use send in conjunction with passing key word args via a variable (as oppose to a literal), I suddenly get a 'wrong number of arguments' error
c.send(:some_method, **kwargs)
Traceback (most recent call last):
5: from /Users/rs/.rvm/rubies/ruby-2.6.7/bin/irb:23:in `<main>'
4: from /Users/rs/.rvm/rubies/ruby-2.6.7/bin/irb:23:in `load'
3: from /Users/rs/.rvm/rubies/ruby-2.6.7/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
2: from (irb):9
1: from (irb):2:in `some_method'
ArgumentError (wrong number of arguments (given 1, expected 0))
Is this intended behavior?

Ruby CSV truncating backtrace

Given the following code:
test.rb
require 'csv'
def meth1
meth2
end
def meth2
begin
iter = CSV.foreach('').each # empty file path, will raise exception.
iter.next
rescue Exception => e
puts e
puts e.backtrace
end
end
meth1
Two questons.
First, why is the backtrace truncated and not showing meth1 or meth2 calls:
No such file or directory # rb_sysopen -
ruby test.rb
/Users/x/.rbenv/versions/2.7.2/lib/ruby/2.7.0/csv.rb:641:in `initialize'
/Users/x/.rbenv/versions/2.7.2/lib/ruby/2.7.0/csv.rb:641:in `open'
/Users/x/.rbenv/versions/2.7.2/lib/ruby/2.7.0/csv.rb:641:in `open'
/Users/x/.rbenv/versions/2.7.2/lib/ruby/2.7.0/csv.rb:510:in `foreach'
test.rb:in `each'
Second, the (truncated) backtrace points to line 641 of CSV (using Ruby v 2.7.2). However line 641 has no initialize() method. Where is this coming from?
.rbenv/versions/2.7.2/lib/ruby/2.7.0/csv.rb
...
begin
f = File.open(filename, mode, **file_opts) ## line 641
rescue ArgumentError => e
raise unless /needs binmode/.match?(e.message) and mode == "r"
mode = "rb"
file_opts = {encoding: Encoding.default_external}.merge(file_opts)
retry
end
If I try another test calling File.open('') directly (instead of through CSV), the resulting backtrace shows everything as expected (including the calls to meth1 and meth2).
Any Ruby gurus out there know what is going on?
I'm not sure I understand; #foreach:510 calls open, #open:641 calls File.open.
In any case, Ruby backtraces have always been a bit wonky, particularly with local top-level files.
The reason you see the initialize is because foreach is a class method of CSV, so there's some behind-the-scenes Ruby shenanigans.
You can use the private method caller_locations, however:
puts e.send(:caller_locations)
which outputs:
test.rb:7:in `meth2'
test.rb:4:in `meth1'
test.rb:20:in `<main>'
This is just the file's top level methods.
You can play games like ruby -d that'll at least get you the line of the script:
Exception `LoadError' at /Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems.rb:1424 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems.rb:1432 - cannot load such file -- rubygems/defaults/ruby
Exception `SyntaxError' at /Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/forwardable/impl.rb:5 - /Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/forwardable/impl.rb:5: syntax error, unexpected end-of-input
Exception `SyntaxError' at /Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/forwardable/impl.rb:5 - /Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/forwardable/impl.rb:5: syntax error, unexpected end-of-input
Exception `Errno::ENOENT' at /Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/csv.rb:641 - No such file or directory # rb_sysopen -
Exception `Errno::ENOENT' at test.rb:10 - No such file or directory # rb_sysopen -
/Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/csv.rb:641:in `initialize'
/Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/csv.rb:641:in `open'
/Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/csv.rb:641:in `open'
/Users/dave/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/csv.rb:510:in `foreach'
test.rb:in `each'
Along with other noise.
If you really want to blow your mind, inside the rescue:
puts Thread.current.backtrace
Which outputs:
test.rb:21:in `backtrace'
test.rb:21:in `rescue in meth2'
test.rb:7:in `meth2'
test.rb:4:in `meth1'
test.rb:35:in `<main>'

Ruby NoMethodError (undefined method ''...' for '....:Class'

require_relative 'json_lookup'
require_relative 'csv_lookup'
require_relative 'error'
BASE_RATE = 'EUR'
class CurrencyExchange
def initialize(file:, date:, from:, to:)
#file = file
#date = date
#from = from
#to = to
end
def rate
lookup = find_lookup
lookup.to_currency / lookup.from_currency
end
private
def find_lookup
case File.extname(#file)
when ".json"
JsonLookup.new(#file, #date, #from, #to)
when ".csv"
CsvLookup.new(#file, #date, #from, #to)
else raise FileError
end
end
end
I keep on getting this error for when i run the CurrencyExchange.rate in irb so I am guessing something is going wrong with the rate method but can't figure it out as to why. But I may be missing something completely obvious... As I am a complete beginner at Ruby, would appreciate any help :)
The traceback is as follows..
irb(main):003:0> CurrencyExchange.rate(Date.new(2018, 11, 22), "USD", "GBP") Traceback (most recent call last):
5: from C:/Ruby26-x64/bin/irb.cmd:31:in `<main>'
4: from C:/Ruby26-x64/bin/irb.cmd:31:in `load'
3: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
2: from (irb):3
1: from (irb):3:in `rescue in irb_binding'
NoMethodError (undefined method `rate' for CurrencyExchange:Class)
rate is an instance method in your example but CurrencyExchange.rate tries to call a class method.
To solve this, initialize an instance first and call then rate on that instance. Furthermore rate doesn't accept arguments, you need to pass the variables to the initializing method.
currency_exchange = CurrencyExchange.new(
file: file, date: Date.new(2018, 11, 22), from: "USD", to: "GBP"
)
currency_exchange.rate
Note take the initializer expects 4 named arguments. You will need to pass a file to the new method too.

RSpec "Failure/Error: Unable to find matching line from backtrace" On every test

I am working through some Ruby problem sets. I'm using Ubuntu 14.04, rbenv 0.4.0-98-g13a474c, rspec 3.1.4, and ruby 2.0.0p353. I'm running into the following errors for every test I run and I'm hoping someone might be able to guide me in the right direction to a solution.
I have run rspec tests successfully in the past but I can't seem to figure out the issue with my current setup.
Here is the message I receive for every test I run:
6) age is an integer
Failure/Error: Unable to find matching line from backtrace
ArgumentError:
wrong number of arguments (0 for 1)
# /usr/lib/ruby/vendor_ruby/rspec/mocks.rb:10:in `setup'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/mocking_adapters/rspec.rb:19:in `setup_mocks_for_rspec'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/example.rb:366:in `run_before_example'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/example.rb:150:in `block in run'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/example.rb:328:in `with_around_example_hooks'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/example.rb:148:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/example_group.rb:500:in `block in run_examples'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/example_group.rb:496:in `map'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/example_group.rb:496:in `run_examples'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/example_group.rb:463:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:111:in `block (2 levels) in run_specs'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:111:in `map'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:111:in `block in run_specs'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/reporter.rb:53:in `report'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:107:in `run_specs'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:85:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:69:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/lib/rspec/core/runner.rb:37:in `invoke'
# /var/lib/gems/1.9.1/gems/rspec-core-3.1.4/exe/rspec:4:in `<top (required)>'
# /usr/local/bin/rspec:23:in `load'
# /usr/local/bin/rspec:23:in `<main>'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
Edit: Here is an example of one of the spec files, however, the issue comes up on about 20 spec files. I know my solutions are correct and my peers aren't having the same issues I am:
first_name = "M"
last_name = "R"
age = 23
describe 'first_name' do
it "is defined as a local variable" do
expect(defined?(first_name)).to eq 'local-variable'
end
it "is a String" do
expect(first_name).to be_a String
end
end
describe 'last_name' do
it "is defined as a local variable" do
expect(defined?(last_name)).to eq 'local-variable'
end
it "be a String" do
expect(last_name).to be_a String
end
end
describe 'age' do
it "is defined as a local variable" do
expect(defined?(age)).to eq 'local-variable'
end
it "is an integer" do
expect(age).to be_a Fixnum
end
end

Rspec any_instance stub causing error undefined method __rspec_original_dup

I'm trying to stub out a Class method for any instance of the class (via any_instance). My tests run through successfully, but at the end of the test when rspec is trying to reset the any_instance stub, it throws an error (Unable to find matching line from backtrace). Here's the apparent culprit line of code (removing it removes the error):
Confetti::Config.any_instance.stub(:write_info)
The full error is below. Seems like stub should've (but fails to) created the __rspec_original_dup method, and when the reset happens, it can't find the expected method.
Failure/Error: Unable to find matching line from backtrace
NameError:
undefined method `__rspec_original_dup' for class `Confetti::Config'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks/any_instance.rb:73:in `alias_method'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks/any_instance.rb:73:in `restore_dup'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks/any_instance.rb:72:in `class_eval'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks/any_instance.rb:72:in `restore_dup'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks/any_instance.rb:46:in `rspec_reset'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks/space.rb:17:in `reset_all'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks/space.rb:16:in `each'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks/space.rb:16:in `reset_all'
# /Library/Ruby/Gems/1.8/gems/rspec-mocks-2.11.1/lib/rspec/mocks.rb:23:in `teardown'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/mocking/with_rspec.rb:18:in `teardown_mocks_for_rspec'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:308:in `run_after_each'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:119:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:253:in `with_around_each_hooks'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:110:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:378:in `run_examples'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `run_examples'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:360:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:34:in `report'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:25:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `autorun'
# /usr/bin/rspec:19
I solved this by simply using Rspec v2.10.0 instead of v2.11.0:
gem 'rspec', '~> 2.10.0'
From the links that Henrik provided, it sounds like they may release a bugfix for Rspec. Watch this issue for more information. In the meantime, downgrading solved the issue for me.
(Thanks for your work in helping me figure this out, Henrik.)

Resources