summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-01-13 12:04:12 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2015-01-13 12:30:12 -0800
commitb1dedaa6e1c3b8f70c16895c7c221286409f9564 (patch)
treec467e93e45df7bdf943573e21333875334951757
parentf0a325ea1a393da4bfd2261c21f8a5aefbf75234 (diff)
downloadchef-b1dedaa6e1c3b8f70c16895c7c221286409f9564.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.rb8
-rw-r--r--lib/chef/knife/cookbook_site_install.rb2
-rw-r--r--spec/unit/knife/cookbook_site_install_spec.rb6
3 files changed, 12 insertions, 4 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index 3b4ed15443..5ef51d5381 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -150,8 +150,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