Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

can't convert Proc into String #285

Closed
ng-pgill opened this issue Nov 1, 2014 · 6 comments
Closed

can't convert Proc into String #285

ng-pgill opened this issue Nov 1, 2014 · 6 comments

Comments

@ng-pgill
Copy link

ng-pgill commented Nov 1, 2014

Ruby version: 1.9.3-p547
Ridley version: 4.1.0

gems/ridley-4.1.0/lib/ridley/client.rb:145:in `expand_path': can't convert Proc into String (TypeError)

in client.rb (line 141):

unless verify_client_key(@options[:client_key])
    @options[:client_key] = File.expand_path(@options[:client_key])
    raise Errors::ClientKeyFileNotFoundOrInvalid, "client key is invalid or not found at: '#{@options[:client_key]}'" unless File.exist?(@options[:client_key]) && verify_client_key(::IO.read(@options[:client_key]))
end

if the :client_key refers to a Proc object, the expand_path call will fail and the error will be can't convert Proc into String.

Would have expect this error:
Ridley::Errors::ClientKeyFileNotFoundOrInvalid client key is invalid or not found at: '/etc/chef/client.pem'

in config.rb (line 50):
we see that a Proc is defined for :client_key

   attribute :client_key,
      default: -> { platform_specific_path('/etc/chef/client.pem') }

I patched client.rb this way for testing:

unless verify_client_key(@options[:client_key])
    if @options[:client_key].kind_of? Proc
        @options[:client_key] = @options[:client_key].call()
    end
    @options[:client_key] = File.expand_path(@options[:client_key])
    raise Errors::ClientKeyFileNotFoundOrInvalid, "client key is invalid or not found at: '#{@options[:client_key]}'" unless File.exist?(@options[:client_key]) && verify_client_key(::IO.read(@options[:client_key]))
end
@andrewgross
Copy link
Contributor

Had this same issue hit me. An unfortunate error message.

@sethvargo
Copy link
Contributor

@pgddevil @andrewgross what command/code are you running that causes this data to be passed in like this? That's true that it's defined as a proc, but varia_model is smart enough to call that proc under certain situations. I'm having trouble finding the code path to make this happen...

@andrewgross
Copy link
Contributor

Hey @sethvargo, here is a rundown of the simplest way to cause the issue for me.

Berkshelf 3.1.5 (via ChefDK)
Running Berkshelf API Local Server (hooked up to my hosted Chef server)
PATH: /opt/chefdk/bin:/Users/awgross/.chefdk/gem/ruby/2.1.0/bin:/opt/chefdk/embedded/bin:/Users/awgross/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/awgross/bin

  1. Create a new cookbook using ChefDK, chef generate cookbook foobar
  2. Point the Berksfile to my local API server, source "http://127.0.0.1:26200"
  3. Add a public (supermarket) dependency in the metadata. I am unsure if this last step is required.
  4. Run berks upload foobar

This will trigger the linked stacktrace. At the time I had this issue, I did not have any file at ~/.berkshelf/config.json, nor did I have any knife configuration files, or any Chef files in /etc. As far as I can tell I had no Chef configuration files in scope.

Stacktrace: https://gist.github.com/andrewgross/95cc2fb31b20a9bd59c1

Let me know if you need more info, or you suspect I am mistaken about how I have my environment setup.

@legal90
Copy link

legal90 commented Nov 26, 2014

I have the same issue too.

@reset Could you please check this out?

@matt-richardson
Copy link

Any progress on this one? Just started facing this one in multiple places (not sure what changed to make it start happening though).

Is the code by @pgddevil acceptable? Can we turn it into a PR and get a fix out?

@brandt
Copy link
Contributor

brandt commented Dec 19, 2014

@matt-richardson I've created a PR to fix this issue in #295

@reset reset closed this as completed in 8022646 Jan 13, 2015
reset added a commit that referenced this issue Jan 13, 2015
Fix #285: Call path proc before expanding
@berkshelf berkshelf locked and limited conversation to collaborators Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants