lib/knife/changelog/policyfile.rb in knife-changelog-1.2.3 vs lib/knife/changelog/policyfile.rb in knife-changelog-1.2.4
- old
+ new
@@ -27,11 +27,11 @@
# @return update_dir [String] tmp directory with updated Policyfile.lock
def update_policyfile_lock
backup_dir = Dir.mktmpdir
FileUtils.cp(File.join(@policyfile_dir, 'Policyfile.lock.json'), backup_dir)
updater = ChefDK::Command::Update.new
- updater.run([@policyfile_path, @cookbooks_to_update].flatten)
+ raise "Error updating Policyfile lock #{@policyfile_path}" unless updater.run([@policyfile_path, @cookbooks_to_update].flatten).zero?
updated_policyfile_lock = read_policyfile_lock(@policyfile_dir)
FileUtils.cp(File.join(backup_dir, 'Policyfile.lock.json'), @policyfile_dir)
updated_policyfile_lock
end
@@ -53,11 +53,11 @@
# @param locks [Hash] cookbook data from Policyfile.lock
# @param type [String] version type - current or target
# @return [Hash] cookbooks with their versions
def versions(locks, type)
raise 'Use "current" or "target" as type' unless %w[current target].include?(type)
- raise 'Cookbook locks empty or nil' if locks.nil? or locks.empty?
+ raise 'Cookbook locks empty or nil' if locks.nil? || locks.empty?
cookbooks = {}
locks.each do |name, data|
cookbooks[name] = if data['source_options'].keys.include?('git')
{ "#{type}_version" => data['source_options']['revision'] }
else
@@ -139,10 +139,11 @@
tags.sort_by do |t|
begin
Gem::Version.new(t.name.gsub(/^v/, ''))
rescue ArgumentError => e
# Skip tag if version is not valid (i.e. a String)
- Gem::Version.new(nil) if e.to_s.include?('Malformed version number string')
+ raise unless e.message && e.message.include?('Malformed version number string')
+ Gem::Version.new('0.0.0')
end
end
end
# Formats commit changelog to be more readable