berkshelf / buff-config

A simple configuration class
Other
5 stars 4 forks source link

Observed exception when client.rb includes Ohai::Config #7

Open xsunsmile opened 10 years ago

xsunsmile commented 10 years ago

I got an exception when using

Ridley.from_chef_config('/etc/chef/client.rb')

I have these extra lines in my /etc/chef/client.rb

Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins"
Ohai::Config[:disabled_plugins] =  []

Here is the stacktrace

/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/buff-config-0.4.0/lib/buff/config/ruby.rb:30:in `rescue in initialize': uninitialized constant Buff::Config::Ruby::Evaluator::Ohai (Buff::Errors::InvalidConfig)
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/buff-config-0.4.0/lib/buff/config/ruby.rb:25:in `initialize'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/buff-config-0.4.0/lib/buff/config/ruby.rb:17:in `new'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/buff-config-0.4.0/lib/buff/config/ruby.rb:17:in `parse'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/buff-config-0.4.0/lib/buff/config/ruby.rb:113:in `from_ruby'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/buff-config-0.4.0/lib/buff/config/ruby.rb:106:in `initialize'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ridley-2.5.1/lib/ridley/chef/config.rb:83:in `initialize'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ridley-2.5.1/lib/ridley.rb:40:in `new'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ridley-2.5.1/lib/ridley.rb:40:in `from_chef_config'
mburns commented 9 years ago

I get the same when running berks in my Chef directory, using the latest version of buff-config (1.0.1) and ruby (2.0.0p481 (2014-05-08 revision 45883).

Commenting out Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins" in my .chef/knife.rb resolves the issue.

/Library/Ruby/Gems/2.0.0/gems/buff-config-1.0.1/lib/buff/config/ruby.rb:30:in `rescue in initialize': uninitialized constant Buff::Config::Ruby::Evaluator::Ohai (Buff::Errors::InvalidConfig)
    from /Library/Ruby/Gems/2.0.0/gems/buff-config-1.0.1/lib/buff/config/ruby.rb:25:in `initialize'
    from /Library/Ruby/Gems/2.0.0/gems/buff-config-1.0.1/lib/buff/config/ruby.rb:17:in `new'
    from /Library/Ruby/Gems/2.0.0/gems/buff-config-1.0.1/lib/buff/config/ruby.rb:17:in `parse'
    from /Library/Ruby/Gems/2.0.0/gems/buff-config-1.0.1/lib/buff/config/ruby.rb:119:in `from_ruby'
    from /Library/Ruby/Gems/2.0.0/gems/buff-config-1.0.1/lib/buff/config/ruby.rb:112:in `initialize'
    from /Library/Ruby/Gems/2.0.0/gems/ridley-4.1.2/lib/ridley/chef/config.rb:83:in `initialize'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf.rb:90:in `new'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf.rb:90:in `chef_config'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf/config.rb:80:in `<class:Config>'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf/config.rb:4:in `<module:Berkshelf>'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf/config.rb:3:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf/cookbook_generator.rb:3:in `require_relative'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf/cookbook_generator.rb:3:in `<class:CookbookGenerator>'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf/cookbook_generator.rb:2:in `<module:Berkshelf>'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf/cookbook_generator.rb:1:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf.rb:197:in `require_relative'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf.rb:197:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:73:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:73:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/lib/berkshelf/cli.rb:1:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:73:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:73:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/berkshelf-3.2.3/bin/berks:3:in `<top (required)>'
    from /usr/bin/berks:23:in `load'
    from /usr/bin/berks:23:in `<main>'
brauliobo commented 9 years ago

same here, nasty error

brauliobo commented 9 years ago

any fix/workaround?

lamont-granquist commented 8 years ago

you might be able to wrap your own code with:

if defined?(Ohai::Config)
  ...
end

berks/ridley/buff-config does not have any idea what Ohai::Config is.

this is a problem with using .rb files for config and then having multiple different contexts that parse the config file.

if it was a json file this couldn't happen, but you'd lose the flexibility that you're losing.