diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 8a9abfdd..25baa1e4 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -12,6 +12,8 @@ require 'monkey_patches' module ModuleSync # rubocop:disable Metrics/ModuleLength + class Error < StandardError; end + include Constants def self.config_defaults @@ -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 @@ -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" diff --git a/lib/modulesync/repository.rb b/lib/modulesync/repository.rb index f5c1f8f9..cd103a37 100644 --- a/lib/modulesync/repository.rb +++ b/lib/modulesync/repository.rb @@ -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