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

Rework exception handling #217

Merged
merged 1 commit into from
Apr 23, 2021
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
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]}'"
neomilium marked this conversation as resolved.
Show resolved Hide resolved
$stderr.puts "#{puppet_module.given_name}: #{message}"
exit 1 unless options[:skip_broken]
errors = true
neomilium marked this conversation as resolved.
Show resolved Hide resolved
$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/)
neomilium marked this conversation as resolved.
Show resolved Hide resolved

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

true
Expand Down