Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require the 'name' attribute is present in metadata.rb #116

Merged
merged 1 commit into from
May 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/kitchen/chef_data_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def cp_cookbooks(tmpdir)
def cp_this_cookbook(tmpdir)
metadata_rb = File.join(kitchen_root, "metadata.rb")
cb_name = MetadataChopper.extract(metadata_rb).first

raise TestKitchen::Errors::MissingCookbookName.new(name) if cb_name.nil?

cb_path = File.join(tmpdir, cb_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I bet this is the issue: if cb_name = nil and tmdir = '/tmp/blah' then effectively:

File.join('/tmp/blah', nil) # TypeError: can't convert nil into String

My bad…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fnichol right, but this error isn't actually raising :(

glob = Dir.glob("#{kitchen_root}/{metadata.rb,README.*," +
"attributes,files,libraries,providers,recipes,resources,templates}")
Expand Down
18 changes: 18 additions & 0 deletions lib/kitchen/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ class ActionFailed < TransientFailure ; end
# Exception class capturing what caused an instance to die.
class InstanceFailure < TransientFailure ; end

# Exception class raised when a cookbook's metadata is missing the name
# attribute.
class MissingCookbookName < StandardError
def initialize(name)
@name = name
end

def to_s
[
"The metadata.rb does not define the 'name' key. Please add:",
"",
" name '#{@name}'",
"",
"to the metadata.rb for '#{@name}' and try again."
].join("\n")
end
end

def self.with_friendly_errors
yield
rescue Kitchen::InstanceFailure => e
Expand Down