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:33:51 -0800 |
commit | 7a6f7d5fa16a906ef2b0e6582c9458b3369573fb (patch) | |
tree | 2c5003c62bd7ded6eb5bd6583bfe449acf3e40c7 | |
parent | af5d79e766c2f8968ea29031eaf0e52154c79755 (diff) | |
download | chef-7a6f7d5fa16a906ef2b0e6582c9458b3369573fb.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 08541441ba..69dbd4ce90 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -136,8 +136,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 |