diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-01-13 12:04:12 -0800 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-01-13 12:04:12 -0800 |
commit | 7b93aaea8ecb14bdc619d443bd81927a9faf5a1f (patch) | |
tree | 01964920064347b6b00ffea5f226eeb7448f322b | |
parent | 15f36de72cc63e8ee986d15fc0db4f0736e3cb1b (diff) | |
parent | ded6262c2c80fd7b3d19e3a2488d503fa989d76c (diff) | |
download | chef-7b93aaea8ecb14bdc619d443bd81927a9faf5a1f.tar.gz |
Merge pull request #2749 from opscode/jdm/metadata-error-info
Provide more info when cookbook metadata is not found
-rw-r--r-- | lib/chef/exceptions.rb | 8 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_install.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_site_install_spec.rb | 6 |
3 files changed, 12 insertions, 4 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index b949e7b975..18b8ee5d3f 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -152,8 +152,12 @@ class Chef class MetadataNotValid < StandardError; end class MetadataNotFound < StandardError - def initialize - super "No metadata.rb or metadata.json!" + attr_reader :install_path + attr_reader :cookbook_name + def initialize(install_path, cookbook_name) + @install_path = install_path + @cookbook_name = cookbook_name + super "No metadata.rb or metadata.json found for cookbook #{@cookbook_name} in #{@install_path}" end end diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb index edf8dd14f0..d0ab6da3ef 100644 --- a/lib/chef/knife/cookbook_site_install.rb +++ b/lib/chef/knife/cookbook_site_install.rb @@ -181,7 +181,7 @@ class Chef return md end - raise Chef::Exceptions::MetadataNotFound + raise Chef::Exceptions::MetadataNotFound.new(@install_path, @cookbook_name) end end end diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb index b3eef32b39..07b268bb64 100644 --- a/spec/unit/knife/cookbook_site_install_spec.rb +++ b/spec/unit/knife/cookbook_site_install_spec.rb @@ -184,7 +184,11 @@ describe Chef::Knife::CookbookSiteInstall do end it "rasies an error if it finds no metadata file" do - expect { knife.preferred_metadata }.to raise_error(Chef::Exceptions::MetadataNotFound) + expect { knife.preferred_metadata }.to raise_error { |error| + expect(error).to be_a(Chef::Exceptions::MetadataNotFound) + expect(error.cookbook_name).to eq("post-punk-kitchen") + expect(error.install_path).to eq(install_path) + } end end |