Skip to content

Commit

Permalink
Fixing error message for missing files/templates, fixes CHEF-1958
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhjk authored and btm committed Sep 29, 2011
1 parent 1d66d73 commit 16a45a4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions chef/lib/chef/cookbook_version.rb
Expand Up @@ -630,14 +630,24 @@ def preferred_manifest_record(node, segment, filename)
if found_pref
@manifest_records_by_path[found_pref]
else
err_msg = "Cookbook '#{name}' (#{version}) does not contain file '#{segment}/default/#{filename}' "
existing_files = segment_filenames(segment)
# Show the files that the cookbook does have. If the user made a typo,
# hopefully they'll see it here.
unless existing_files.empty?
err_msg << "This cookbook _does_ contain: ['#{existing_files.join("','")}']"
if segment == :files || segment == :templates
error_message = "Cookbook '#{name}' (#{version}) does not contain a file at any of these locations:\n"
error_locations = [
" #{segment}/#{node[:platform]}-#{node[:platform_version]}/#{filename}",
" #{segment}/#{node[:platform]}/#{filename}",
" #{segment}/default/#{filename}",
]
error_message << error_locations.join("\n")
existing_files = segment_filenames(segment)
# Show the files that the cookbook does have. If the user made a typo,
# hopefully they'll see it here.
unless existing_files.empty?
error_message << "\n\nThis cookbook _does_ contain: ['#{existing_files.join("','")}']"
end
raise Chef::Exceptions::FileNotFound, error_message
else
raise Chef::Exceptions::FileNotFound, "cookbook #{name} does not contain file #{segment}/#{filename}"
end
raise Chef::Exceptions::FileNotFound, err_msg
end
end

Expand Down

0 comments on commit 16a45a4

Please sign in to comment.