Skip to content

Commit

Permalink
Merge pull request #217 from opus-codium/rework-exception-handling
Browse files Browse the repository at this point in the history
Rework exception handling
  • Loading branch information
ekohl authored Apr 23, 2021
2 parents e22daf8 + 8093878 commit 44b3e75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
15 changes: 11 additions & 4 deletions lib/modulesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
require 'monkey_patches'

module ModuleSync # rubocop:disable Metrics/ModuleLength
class Error < StandardError; end

include Constants

def self.config_defaults
Expand Down Expand Up @@ -98,8 +100,8 @@ def self.manage_file(puppet_module, filename, settings, options)
}
template = Renderer.render(erb, configs, metadata)
Renderer.sync(template, target_file)
rescue # rubocop:disable Lint/RescueWithoutErrorClass
$stderr.puts "Error while rendering #{filename}"
rescue StandardError => e
$stderr.puts "#{puppet_module.given_name}: Error while rendering file: '#{filename}'"
raise
end
end
Expand Down Expand Up @@ -173,8 +175,13 @@ def self.update(cli_options)
managed_modules.each do |puppet_module|
begin
manage_module(puppet_module, module_files, defaults)
rescue # rubocop:disable Lint/RescueWithoutErrorClass
warn "Error while updating '#{puppet_module.given_name}'"
rescue ModuleSync::Error, Git::GitExecuteError => e
message = e.message || "Error during '#{options[:command]}'"
$stderr.puts "#{puppet_module.given_name}: #{message}"
exit 1 unless options[:skip_broken]
errors = true
$stdout.puts "Skipping '#{puppet_module.given_name}' as update process failed"
rescue StandardError => e
raise unless options[:skip_broken]
errors = true
$stdout.puts "Skipping '#{puppet_module.given_name}' as update process failed"
Expand Down
11 changes: 4 additions & 7 deletions lib/modulesync/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,10 @@ def submit_changes(files, options)
repo.push('origin', branch, opts_push)
end
rescue Git::GitExecuteError => e
if e.message.match?(/working (directory|tree) clean/)
puts "There were no changes in '#{@directory}'. Not committing."
return false
else
puts e
raise
end
raise unless e.message.match?(/working (directory|tree) clean/)

puts "There were no changes in '#{@directory}'. Not committing."
return false
end

true
Expand Down

0 comments on commit 44b3e75

Please sign in to comment.