Skip to content

refactor: wrap rescue inside begin / end block #584

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

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 11 additions & 9 deletions lib/facter/vcsrepo_svn_ver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

Facter.add(:vcsrepo_svn_ver) do
setcode do
if Facter.value(:operatingsystem) == 'Darwin' && !File.directory?(Facter::Core::Execution.execute('xcode-select -p'))
''
else
version = Facter::Core::Execution.execute('svn --version --quiet')
if Gem::Version.new(version) > Gem::Version.new('0.0.1')
version
else
begin
if Facter.value(:operatingsystem) == 'Darwin' && !File.directory?(Facter::Core::Execution.execute('xcode-select -p'))
''
else
version = Facter::Core::Execution.execute('svn --version --quiet')
if Gem::Version.new(version) > Gem::Version.new('0.0.1')
version
else
''
end
end
rescue StandardError
''
end
rescue StandardError
''
end
end
8 changes: 5 additions & 3 deletions lib/puppet/provider/vcsrepo/bzr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ def revision

def revision=(desired)
at_path do
bzr('update', '-r', desired)
rescue Puppet::ExecutionFailure
bzr('update', '-r', desired, ':parent')
begin
bzr('update', '-r', desired)
rescue Puppet::ExecutionFailure
bzr('update', '-r', desired, ':parent')
end
end
update_owner
end
Expand Down
38 changes: 22 additions & 16 deletions lib/puppet/provider/vcsrepo/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,12 @@ def convert_bare_to_working_copy

def mirror?
at_path do
git_with_identity('config', '--get-regexp', 'remote\..*\.mirror')
return true
rescue Puppet::ExecutionFailure
return false
begin
git_with_identity('config', '--get-regexp', 'remote\..*\.mirror')
return true
rescue Puppet::ExecutionFailure
return false
end
end
end

Expand All @@ -310,17 +312,21 @@ def set_mirror

def set_no_mirror
at_path do
if @resource.value(:source).is_a?(String)
begin
exec_git('config', '--unset', "remote.#{@resource.value(:remote)}.mirror")
rescue Puppet::ExecutionFailure
next
end
else
@resource.value(:source).each_key do |remote|
exec_git('config', '--unset', "remote.#{remote}.mirror")
rescue Puppet::ExecutionFailure
next
begin
if @resource.value(:source).is_a?(String)
begin
exec_git('config', '--unset', "remote.#{@resource.value(:remote)}.mirror")
rescue Puppet::ExecutionFailure
next
end
else
@resource.value(:source).each_key do |remote|
begin
exec_git('config', '--unset', "remote.#{remote}.mirror")
rescue Puppet::ExecutionFailure
next
end
end
end
end
end
Expand Down Expand Up @@ -721,7 +727,7 @@ def exec_git(*args)
exec_args[:uid] = @resource.value(:user)
end
withumask do
Puppet::Util::Execution.execute([:git, args], **exec_args)
Puppet::Util::Execution.execute([:git, args], exec_args)
end
end
end
10 changes: 6 additions & 4 deletions lib/puppet/provider/vcsrepo/hg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ def latest?

def latest
at_path do
hg_wrapper('incoming', '--branch', '.', '--newest-first', '--limit', '1', remote: true)[%r{^changeset:\s+(?:-?\d+):(\S+)}m, 1]
rescue Puppet::ExecutionFailure
# If there are no new changesets, return the current nodeid
revision
begin
hg_wrapper('incoming', '--branch', '.', '--newest-first', '--limit', '1', remote: true)[%r{^changeset:\s+(?:-?\d+):(\S+)}m, 1]
rescue Puppet::ExecutionFailure
# If there are no new changesets, return the current nodeid
revision
end
end
end

Expand Down