summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/application/apply.rb10
-rw-r--r--lib/chef/application/windows_service.rb54
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb108
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/acl_entry.rb20
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb16
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb16
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb32
-rw-r--r--lib/chef/client.rb20
-rw-r--r--lib/chef/dsl/platform_introspection.rb14
-rw-r--r--lib/chef/file_content_management/tempfile.rb18
-rw-r--r--lib/chef/knife/cookbook_upload.rb46
-rw-r--r--lib/chef/knife/delete.rb30
-rw-r--r--lib/chef/knife/ssh.rb12
-rw-r--r--lib/chef/knife/xargs.rb38
-rw-r--r--lib/chef/monkey_patches/webrick-utils.rb20
-rw-r--r--lib/chef/provider/git.rb10
-rw-r--r--lib/chef/provider/group/suse.rb10
-rw-r--r--lib/chef/provider/package/windows/registry_uninstall_entry.rb18
-rw-r--r--lib/chef/provider/service/windows.rb20
-rw-r--r--lib/chef/provider/user/mac.rb18
-rw-r--r--lib/chef/resource.rb10
-rw-r--r--lib/chef/resource/chef_vault_secret.rb26
-rw-r--r--lib/chef/resource/sysctl.rb10
-rw-r--r--lib/chef/run_context/cookbook_compiler.rb38
-rw-r--r--lib/chef/util/diff.rb20
-rw-r--r--lib/chef/win32/file/version_info.rb10
26 files changed, 322 insertions, 322 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index c8c0c0eaf6..8d64c48102 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -213,11 +213,11 @@ class Chef::Application::Apply < Chef::Application
end
runner = Chef::Runner.new(run_context)
catch(:end_client_run_early) do
- begin
- runner.converge
- ensure
- @recipe_fh.close
- end
+
+ runner.converge
+ ensure
+ @recipe_fh.close
+
end
Chef::Platform::Rebooter.reboot_if_needed!(runner)
end
diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb
index 9f3781e8a1..770a5644ca 100644
--- a/lib/chef/application/windows_service.rb
+++ b/lib/chef/application/windows_service.rb
@@ -78,33 +78,33 @@ class Chef
while running?
# Grab the service_action_mutex to make a chef-client run
@service_action_mutex.synchronize do
- begin
- Chef::Log.info("Next #{Chef::Dist::CLIENT} run will happen in #{timeout} seconds")
- @service_signal.wait(@service_action_mutex, timeout)
-
- # Continue only if service is RUNNING
- next if state != RUNNING
-
- # Reconfigure each time through to pick up any changes in the client file
- Chef::Log.info("Reconfiguring with startup parameters")
- reconfigure(startup_parameters)
- timeout = Chef::Config[:interval]
-
- # Honor splay sleep config
- timeout += rand Chef::Config[:splay]
-
- # run chef-client only if service is in RUNNING state
- next if state != RUNNING
-
- Chef::Log.info("#{Chef::Dist::CLIENT} service is starting a #{Chef::Dist::CLIENT} run...")
- run_chef_client
- rescue SystemExit => e
- # Do not raise any of the errors here in order to
- # prevent service crash
- Chef::Log.error("#{e.class}: #{e}")
- rescue Exception => e
- Chef::Log.error("#{e.class}: #{e}")
- end
+
+ Chef::Log.info("Next #{Chef::Dist::CLIENT} run will happen in #{timeout} seconds")
+ @service_signal.wait(@service_action_mutex, timeout)
+
+ # Continue only if service is RUNNING
+ next if state != RUNNING
+
+ # Reconfigure each time through to pick up any changes in the client file
+ Chef::Log.info("Reconfiguring with startup parameters")
+ reconfigure(startup_parameters)
+ timeout = Chef::Config[:interval]
+
+ # Honor splay sleep config
+ timeout += rand Chef::Config[:splay]
+
+ # run chef-client only if service is in RUNNING state
+ next if state != RUNNING
+
+ Chef::Log.info("#{Chef::Dist::CLIENT} service is starting a #{Chef::Dist::CLIENT} run...")
+ run_chef_client
+ rescue SystemExit => e
+ # Do not raise any of the errors here in order to
+ # prevent service crash
+ Chef::Log.error("#{e.class}: #{e}")
+ rescue Exception => e
+ Chef::Log.error("#{e.class}: #{e}")
+
end
end
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb
index 8237729e89..d7541a592e 100644
--- a/lib/chef/chef_fs/chef_fs_data_store.rb
+++ b/lib/chef/chef_fs/chef_fs_data_store.rb
@@ -172,11 +172,11 @@ class Chef
@memory_store.create_dir(path, name, *options)
else
with_parent_dir(path + [name], *options) do |parent, name|
- begin
- parent.create_child(name, nil)
- rescue Chef::ChefFS::FileSystem::AlreadyExistsError => e
- raise ChefZero::DataStore::DataAlreadyExistsError.new(to_zero_path(e.entry), e)
- end
+
+ parent.create_child(name, nil)
+ rescue Chef::ChefFS::FileSystem::AlreadyExistsError => e
+ raise ChefZero::DataStore::DataAlreadyExistsError.new(to_zero_path(e.entry), e)
+
end
end
end
@@ -251,11 +251,11 @@ class Chef
end
with_parent_dir(path + [name], *options) do |parent, name|
- begin
- parent.create_child(name, data)
- rescue Chef::ChefFS::FileSystem::AlreadyExistsError => e
- raise ChefZero::DataStore::DataAlreadyExistsError.new(to_zero_path(e.entry), e)
- end
+
+ parent.create_child(name, data)
+ rescue Chef::ChefFS::FileSystem::AlreadyExistsError => e
+ raise ChefZero::DataStore::DataAlreadyExistsError.new(to_zero_path(e.entry), e)
+
end
end
end
@@ -349,11 +349,11 @@ class Chef
else
with_entry(path) do |entry|
- begin
- entry.read
- rescue Chef::ChefFS::FileSystem::NotFoundError => e
- raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
- end
+
+ entry.read
+ rescue Chef::ChefFS::FileSystem::NotFoundError => e
+ raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
+
end
end
end
@@ -433,15 +433,15 @@ class Chef
else
with_entry(path) do |entry|
- begin
- if %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length >= 3
- entry.delete(true)
- else
- entry.delete(false)
- end
- rescue Chef::ChefFS::FileSystem::NotFoundError => e
- raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
+
+ if %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length >= 3
+ entry.delete(true)
+ else
+ entry.delete(false)
end
+ rescue Chef::ChefFS::FileSystem::NotFoundError => e
+ raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
+
end
end
end
@@ -471,11 +471,11 @@ class Chef
else
with_entry(path) do |entry|
- begin
- entry.delete(options.include?(:recursive))
- rescue Chef::ChefFS::FileSystem::NotFoundError => e
- raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
- end
+
+ entry.delete(options.include?(:recursive))
+ rescue Chef::ChefFS::FileSystem::NotFoundError => e
+ raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
+
end
end
end
@@ -487,11 +487,11 @@ class Chef
# LIST /policies
elsif path == [ "policies" ]
with_entry([ path[0] ]) do |policies|
- begin
- policies.children.map { |policy| policy.name[0..-6].rpartition("-")[0] }.uniq
- rescue Chef::ChefFS::FileSystem::NotFoundError
- []
- end
+
+ policies.children.map { |policy| policy.name[0..-6].rpartition("-")[0] }.uniq
+ rescue Chef::ChefFS::FileSystem::NotFoundError
+ []
+
end
# LIST /policies/POLICY/revisions
@@ -524,19 +524,19 @@ class Chef
elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 1
with_entry(path) do |entry|
- begin
- if path[0] == "cookbook_artifacts"
- entry.children.map { |child| child.name.rpartition("-")[0] }.uniq
- elsif chef_fs.versioned_cookbooks
- # /cookbooks/name-version -> /cookbooks/name
- entry.children.map { |child| split_name_version(child.name)[0] }.uniq
- else
- entry.children.map(&:name)
- end
- rescue Chef::ChefFS::FileSystem::NotFoundError
- # If the cookbooks dir doesn't exist, we have no cookbooks (not 404)
- []
+
+ if path[0] == "cookbook_artifacts"
+ entry.children.map { |child| child.name.rpartition("-")[0] }.uniq
+ elsif chef_fs.versioned_cookbooks
+ # /cookbooks/name-version -> /cookbooks/name
+ entry.children.map { |child| split_name_version(child.name)[0] }.uniq
+ else
+ entry.children.map(&:name)
end
+ rescue Chef::ChefFS::FileSystem::NotFoundError
+ # If the cookbooks dir doesn't exist, we have no cookbooks (not 404)
+ []
+
end
elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 2
@@ -560,16 +560,16 @@ class Chef
else
result = with_entry(path) do |entry|
- begin
- entry.children.map { |c| zero_filename(c) }.sort
- rescue Chef::ChefFS::FileSystem::NotFoundError => e
- # /cookbooks, /data, etc. never return 404
- if path_always_exists?(path)
- []
- else
- raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
- end
+
+ entry.children.map { |c| zero_filename(c) }.sort
+ rescue Chef::ChefFS::FileSystem::NotFoundError => e
+ # /cookbooks, /data, etc. never return 404
+ if path_always_exists?(path)
+ []
+ else
+ raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
end
+
end
# Older versions of chef-zero do not understand policies and cookbook_artifacts,
diff --git a/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb b/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
index adf3c26cda..db29ce7ba7 100644
--- a/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
@@ -47,17 +47,17 @@ class Chef
# ACL writes are fun.
acls = data_handler.normalize(Chef::JSONCompat.parse(file_contents), self)
PERMISSIONS.each do |permission|
- begin
- rest.put("#{api_path}/#{permission}", { permission => acls[permission] })
- rescue Timeout::Error => e
- raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}")
- rescue Net::HTTPClientException => e
- if e.response.code == "404"
- raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
- else
- raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "HTTP error writing: #{e}")
- end
+
+ rest.put("#{api_path}/#{permission}", { permission => acls[permission] })
+ rescue Timeout::Error => e
+ raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}")
+ rescue Net::HTTPClientException => e
+ if e.response.code == "404"
+ raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
+ else
+ raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "HTTP error writing: #{e}")
end
+
end
end
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb b/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb
index bcb6b94edf..d852a3bc2e 100644
--- a/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb
@@ -44,15 +44,15 @@ class Chef
actual_invites = _read_json.inject({}) { |h, val| h[val["username"]] = val["id"]; h }
invites = actual_invites.keys
(desired_invites - invites).each do |invite|
- begin
- rest.post(api_path, { "user" => invite })
- rescue Net::HTTPClientException => e
- if e.response.code == "409"
- Chef::Log.warn("Could not invite #{invite} to organization #{org}: #{api_error_text(e.response)}")
- else
- raise
- end
+
+ rest.post(api_path, { "user" => invite })
+ rescue Net::HTTPClientException => e
+ if e.response.code == "409"
+ Chef::Log.warn("Could not invite #{invite} to organization #{org}: #{api_error_text(e.response)}")
+ else
+ raise
end
+
end
(invites - desired_invites).each do |invite|
rest.delete(File.join(api_path, actual_invites[invite]))
diff --git a/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb b/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb
index 31c5f880f8..ded890cc32 100644
--- a/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb
@@ -43,15 +43,15 @@ class Chef
desired_members = minimize_value(Chef::JSONCompat.parse(contents, create_additions: false))
members = minimize_value(_read_json)
(desired_members - members).each do |member|
- begin
- rest.post(api_path, "username" => member)
- rescue Net::HTTPClientException => e
- if %w{404 405}.include?(e.response.code)
- raise "Chef server at #{api_path} does not allow you to directly add members. Please either upgrade your Chef server or move the users you want into invitations.json instead of members.json."
- else
- raise
- end
+
+ rest.post(api_path, "username" => member)
+ rescue Net::HTTPClientException => e
+ if %w{404 405}.include?(e.response.code)
+ raise "Chef server at #{api_path} does not allow you to directly add members. Please either upgrade your Chef server or move the users you want into invitations.json instead of members.json."
+ else
+ raise
end
+
end
(members - desired_members).each do |member|
rest.delete(File.join(api_path, member))
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
index 431b9ecb22..c384113a02 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
@@ -109,23 +109,23 @@ class Chef
child = root_dir.create_child(name, file_contents)
else
child_paths[name].each do |path|
- begin
- ::FileUtils.mkdir_p(path)
- ::FileUtils.chmod(0700, path)
- if ChefUtils.windows?
- all_mask = Chef::ReservedNames::Win32::API::Security::GENERIC_ALL
- administrators = Chef::ReservedNames::Win32::Security::SID.Administrators
- owner = Chef::ReservedNames::Win32::Security::SID.default_security_object_owner
- dacl = Chef::ReservedNames::Win32::Security::ACL.create([
- Chef::ReservedNames::Win32::Security::ACE.access_allowed(owner, all_mask),
- Chef::ReservedNames::Win32::Security::ACE.access_allowed(administrators, all_mask),
- ])
- so = Chef::ReservedNames::Win32::Security::SecurableObject.new(path)
- so.owner = owner
- so.set_dacl(dacl, false)
- end
- rescue Errno::EEXIST
+
+ ::FileUtils.mkdir_p(path)
+ ::FileUtils.chmod(0700, path)
+ if ChefUtils.windows?
+ all_mask = Chef::ReservedNames::Win32::API::Security::GENERIC_ALL
+ administrators = Chef::ReservedNames::Win32::Security::SID.Administrators
+ owner = Chef::ReservedNames::Win32::Security::SID.default_security_object_owner
+ dacl = Chef::ReservedNames::Win32::Security::ACL.create([
+ Chef::ReservedNames::Win32::Security::ACE.access_allowed(owner, all_mask),
+ Chef::ReservedNames::Win32::Security::ACE.access_allowed(administrators, all_mask),
+ ])
+ so = Chef::ReservedNames::Win32::Security::SecurableObject.new(path)
+ so.owner = owner
+ so.set_dacl(dacl, false)
end
+ rescue Errno::EEXIST
+
end
child = make_child_entry(name)
end
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 1e069be185..c0f1eddc9d 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -707,16 +707,16 @@ class Chef
#
def converge(run_context)
catch(:end_client_run_early) do
- begin
- events.converge_start(run_context)
- logger.debug("Converging node #{node_name}")
- @runner = Chef::Runner.new(run_context)
- @runner.converge
- events.converge_complete
- rescue Exception => e
- events.converge_failed(e)
- raise e
- end
+
+ events.converge_start(run_context)
+ logger.debug("Converging node #{node_name}")
+ @runner = Chef::Runner.new(run_context)
+ @runner.converge
+ events.converge_complete
+ rescue Exception => e
+ events.converge_failed(e)
+ raise e
+
end
end
diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb
index 8755644689..98ea9dc670 100644
--- a/lib/chef/dsl/platform_introspection.rb
+++ b/lib/chef/dsl/platform_introspection.rb
@@ -79,14 +79,14 @@ class Chef
key_matches = []
keys = @values[platform].keys
keys.each do |k|
- begin
- if Chef::VersionConstraint::Platform.new(k).include?(node_version)
- key_matches << k
- end
- rescue Chef::Exceptions::InvalidVersionConstraint => e
- Chef::Log.trace "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
- Chef::Log.trace(e)
+
+ if Chef::VersionConstraint::Platform.new(k).include?(node_version)
+ key_matches << k
end
+ rescue Chef::Exceptions::InvalidVersionConstraint => e
+ Chef::Log.trace "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
+ Chef::Log.trace(e)
+
end
return @values[platform][version] if key_matches.include?(version)
diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb
index 46ab4a7e72..763648de33 100644
--- a/lib/chef/file_content_management/tempfile.rb
+++ b/lib/chef/file_content_management/tempfile.rb
@@ -39,15 +39,15 @@ class Chef
errors = [ ]
tempfile_dirnames.each do |tempfile_dirname|
- begin
- # preserving the file extension of the target filename should be considered a public API
- tf = ::Tempfile.open([tempfile_basename, tempfile_extension], tempfile_dirname)
- break
- rescue SystemCallError => e
- message = "Creating temp file under '#{tempfile_dirname}' failed with: '#{e.message}'"
- Chef::Log.trace(message)
- errors << message
- end
+
+ # preserving the file extension of the target filename should be considered a public API
+ tf = ::Tempfile.open([tempfile_basename, tempfile_extension], tempfile_dirname)
+ break
+ rescue SystemCallError => e
+ message = "Creating temp file under '#{tempfile_dirname}' failed with: '#{e.message}'"
+ Chef::Log.trace(message)
+ errors << message
+
end
raise Chef::Exceptions::FileContentStagingError, errors if tf.nil?
diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb
index b87aea7e04..9f6f3c4cb2 100644
--- a/lib/chef/knife/cookbook_upload.rb
+++ b/lib/chef/knife/cookbook_upload.rb
@@ -132,20 +132,20 @@ class Chef
end
else
tmp_cl.each do |cookbook_name, cookbook|
- begin
- upload([cookbook], justify_width)
- upload_ok += 1
- rescue Exceptions::CookbookNotFoundInRepo => e
- upload_failures += 1
- ui.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
- Log.debug(e)
- upload_failures += 1
- rescue Exceptions::CookbookFrozen
- ui.warn("Not updating version constraints for #{cookbook_name} in the environment as the cookbook is frozen.")
- upload_failures += 1
- rescue SystemExit => e
- raise exit e.status
- end
+
+ upload([cookbook], justify_width)
+ upload_ok += 1
+ rescue Exceptions::CookbookNotFoundInRepo => e
+ upload_failures += 1
+ ui.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
+ Log.debug(e)
+ upload_failures += 1
+ rescue Exceptions::CookbookFrozen
+ ui.warn("Not updating version constraints for #{cookbook_name} in the environment as the cookbook is frozen.")
+ upload_failures += 1
+ rescue SystemExit => e
+ raise exit e.status
+
end
if upload_failures == 0
@@ -172,17 +172,17 @@ class Chef
else
upload_set = {}
@name_args.each do |cookbook_name|
- begin
- unless upload_set.key?(cookbook_name)
- upload_set[cookbook_name] = cookbook_repo[cookbook_name]
- if config[:depends]
- upload_set[cookbook_name].metadata.dependencies.each_key { |dep| @name_args << dep }
- end
+
+ unless upload_set.key?(cookbook_name)
+ upload_set[cookbook_name] = cookbook_repo[cookbook_name]
+ if config[:depends]
+ upload_set[cookbook_name].metadata.dependencies.each_key { |dep| @name_args << dep }
end
- rescue Exceptions::CookbookNotFoundInRepo => e
- ui.error(e.message)
- Log.debug(e)
end
+ rescue Exceptions::CookbookNotFoundInRepo => e
+ ui.error(e.message)
+ Log.debug(e)
+
end
upload_set
end
diff --git a/lib/chef/knife/delete.rb b/lib/chef/knife/delete.rb
index d1888e127a..3e5c545017 100644
--- a/lib/chef/knife/delete.rb
+++ b/lib/chef/knife/delete.rb
@@ -96,21 +96,21 @@ class Chef
found_any = false
error = false
results.each do |result|
- begin
- result.delete(config[:recurse])
- deleted_any = true
- found_any = true
- rescue Chef::ChefFS::FileSystem::NotFoundError
- # This is not an error unless *all* of them were not found
- rescue Chef::ChefFS::FileSystem::MustDeleteRecursivelyError => e
- ui.error "#{format_path_with_root(e.entry)} must be deleted recursively! Pass -r to knife delete."
- found_any = true
- error = true
- rescue Chef::ChefFS::FileSystem::OperationNotAllowedError => e
- ui.error "#{format_path_with_root(e.entry)} #{e.reason}."
- found_any = true
- error = true
- end
+
+ result.delete(config[:recurse])
+ deleted_any = true
+ found_any = true
+ rescue Chef::ChefFS::FileSystem::NotFoundError
+ # This is not an error unless *all* of them were not found
+ rescue Chef::ChefFS::FileSystem::MustDeleteRecursivelyError => e
+ ui.error "#{format_path_with_root(e.entry)} must be deleted recursively! Pass -r to knife delete."
+ found_any = true
+ error = true
+ rescue Chef::ChefFS::FileSystem::OperationNotAllowedError => e
+ ui.error "#{format_path_with_root(e.entry)} #{e.reason}."
+ found_any = true
+ error = true
+
end
if deleted_any
output("Deleted #{format_path(results[0])}")
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index 433ce1e482..5e856ec011 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -525,12 +525,12 @@ class Chef
def cssh
cssh_cmd = nil
%w{csshX cssh}.each do |cmd|
- begin
- # Unix and Mac only
- cssh_cmd = shell_out!("which #{cmd}").stdout.strip
- break
- rescue Mixlib::ShellOut::ShellCommandFailed
- end
+
+ # Unix and Mac only
+ cssh_cmd = shell_out!("which #{cmd}").stdout.strip
+ break
+ rescue Mixlib::ShellOut::ShellCommandFailed
+
end
raise Chef::Exceptions::Exec, "no command found for cssh" unless cssh_cmd
diff --git a/lib/chef/knife/xargs.rb b/lib/chef/knife/xargs.rb
index 13135ba47c..9dcc724d38 100644
--- a/lib/chef/knife/xargs.rb
+++ b/lib/chef/knife/xargs.rb
@@ -204,25 +204,25 @@ class Chef
error = false
# Create the temporary files
tempfiles.each_pair do |tempfile, file|
- begin
- value = file[:file].read
- file[:value] = value
- tempfile.open
- tempfile.write(value)
- tempfile.close
- rescue Chef::ChefFS::FileSystem::OperationNotAllowedError => e
- ui.error "#{format_path(e.entry)}: #{e.reason}."
- error = true
- tempfile.close!
- tempfiles.delete(tempfile)
- next
- rescue Chef::ChefFS::FileSystem::NotFoundError => e
- ui.error "#{format_path(e.entry)}: No such file or directory"
- error = true
- tempfile.close!
- tempfiles.delete(tempfile)
- next
- end
+
+ value = file[:file].read
+ file[:value] = value
+ tempfile.open
+ tempfile.write(value)
+ tempfile.close
+ rescue Chef::ChefFS::FileSystem::OperationNotAllowedError => e
+ ui.error "#{format_path(e.entry)}: #{e.reason}."
+ error = true
+ tempfile.close!
+ tempfiles.delete(tempfile)
+ next
+ rescue Chef::ChefFS::FileSystem::NotFoundError => e
+ ui.error "#{format_path(e.entry)}: No such file or directory"
+ error = true
+ tempfile.close!
+ tempfiles.delete(tempfile)
+ next
+
end
return error if error && tempfiles.size == 0
diff --git a/lib/chef/monkey_patches/webrick-utils.rb b/lib/chef/monkey_patches/webrick-utils.rb
index fa52a753c4..6e3748f308 100644
--- a/lib/chef/monkey_patches/webrick-utils.rb
+++ b/lib/chef/monkey_patches/webrick-utils.rb
@@ -33,16 +33,16 @@ module WEBrick
last_error = nil
sockets = []
res.each do |ai|
- begin
- logger.debug("TCPServer.new(#{ai[3]}, #{port})") if logger
- sock = TCPServer.new(ai[3], port)
- port = sock.addr[1] if port == 0
- Utils.set_close_on_exec(sock)
- sockets << sock
- rescue => ex
- logger.warn("TCPServer Error: #{ex}") if logger
- last_error = ex
- end
+
+ logger.debug("TCPServer.new(#{ai[3]}, #{port})") if logger
+ sock = TCPServer.new(ai[3], port)
+ port = sock.addr[1] if port == 0
+ Utils.set_close_on_exec(sock)
+ sockets << sock
+ rescue => ex
+ logger.warn("TCPServer Error: #{ex}") if logger
+ last_error = ex
+
end
raise last_error if sockets.empty?
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index 6f5a129820..f1c8380307 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -44,11 +44,11 @@ class Chef
unless new_resource.user.nil?
requirements.assert(:all_actions) do |a|
a.assertion do
- begin
- get_homedir(new_resource.user)
- rescue ArgumentError
- false
- end
+
+ get_homedir(new_resource.user)
+ rescue ArgumentError
+ false
+
end
a.whyrun("User #{new_resource.user} does not exist, this run will fail unless it has been previously created. Assuming it would have been created.")
a.failure_message(Chef::Exceptions::User, "#{new_resource.user} required by resource #{new_resource.name} does not exist")
diff --git a/lib/chef/provider/group/suse.rb b/lib/chef/provider/group/suse.rb
index 0fecc05e22..266e8e0fbc 100644
--- a/lib/chef/provider/group/suse.rb
+++ b/lib/chef/provider/group/suse.rb
@@ -39,11 +39,11 @@ class Chef
requirements.assert(:create, :manage, :modify) do |a|
a.assertion do
- begin
- to_add(new_resource.members).all? { |member| Etc.getpwnam(member) }
- rescue
- false
- end
+
+ to_add(new_resource.members).all? { |member| Etc.getpwnam(member) }
+ rescue
+ false
+
end
a.failure_message Chef::Exceptions::Group, "Could not add users #{to_add(new_resource.members).join(", ")} to #{new_resource.group_name}: one of these users does not exist"
a.whyrun "Could not find one of these users: #{to_add(new_resource.members).join(", ")}. Assuming it will be created by a prior step"
diff --git a/lib/chef/provider/package/windows/registry_uninstall_entry.rb b/lib/chef/provider/package/windows/registry_uninstall_entry.rb
index 548b911ecb..f1814d5dcf 100644
--- a/lib/chef/provider/package/windows/registry_uninstall_entry.rb
+++ b/lib/chef/provider/package/windows/registry_uninstall_entry.rb
@@ -37,16 +37,16 @@ class Chef
begin
::Win32::Registry.open(hkey[0], UNINSTALL_SUBKEY, desired) do |reg|
reg.each_key do |key, _wtime|
- begin
- entry = reg.open(key, desired)
- display_name = read_registry_property(entry, "DisplayName")
- if display_name.to_s.rstrip == package_name
- quiet_uninstall_string = RegistryUninstallEntry.read_registry_property(entry, "QuietUninstallString")
- entries.push(quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry))
- end
- rescue ::Win32::Registry::Error => ex
- logger.trace("Registry error opening key '#{key}' on node #{desired}: #{ex}")
+
+ entry = reg.open(key, desired)
+ display_name = read_registry_property(entry, "DisplayName")
+ if display_name.to_s.rstrip == package_name
+ quiet_uninstall_string = RegistryUninstallEntry.read_registry_property(entry, "QuietUninstallString")
+ entries.push(quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry))
end
+ rescue ::Win32::Registry::Error => ex
+ logger.trace("Registry error opening key '#{key}' on node #{desired}: #{ex}")
+
end
end
rescue ::Win32::Registry::Error => ex
diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb
index 88bb282be9..98aad4fe29 100644
--- a/lib/chef/provider/service/windows.rb
+++ b/lib/chef/provider/service/windows.rb
@@ -95,17 +95,17 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
shell_out!(@new_resource.start_command)
else
spawn_command_thread do
- begin
- Win32::Service.start(@new_resource.service_name)
- rescue SystemCallError => ex
- if ex.errno == ERROR_SERVICE_LOGON_FAILED
- logger.error ex.message
- raise Chef::Exceptions::Service,
- "Service #{@new_resource} did not start due to a logon failure (error #{ERROR_SERVICE_LOGON_FAILED}): possibly the specified user '#{@new_resource.run_as_user}' does not have the 'log on as a service' privilege, or the password is incorrect."
- else
- raise ex
- end
+
+ Win32::Service.start(@new_resource.service_name)
+ rescue SystemCallError => ex
+ if ex.errno == ERROR_SERVICE_LOGON_FAILED
+ logger.error ex.message
+ raise Chef::Exceptions::Service,
+ "Service #{@new_resource} did not start due to a logon failure (error #{ERROR_SERVICE_LOGON_FAILED}): possibly the specified user '#{@new_resource.run_as_user}' does not have the 'log on as a service' privilege, or the password is incorrect."
+ else
+ raise ex
end
+
end
wait_for_state(RUNNING)
end
diff --git a/lib/chef/provider/user/mac.rb b/lib/chef/provider/user/mac.rb
index 34307aff1e..9ae1628d5c 100644
--- a/lib/chef/provider/user/mac.rb
+++ b/lib/chef/provider/user/mac.rb
@@ -583,16 +583,16 @@ class Chef
timeout = Time.now + 5
loop do
- begin
- run_dscl("read", "/Users/#{new_resource.username}", "ShadowHashData")
- break
- rescue Chef::Exceptions::DsclCommandFailed => e
- if Time.now < timeout
- sleep 0.1
- else
- raise Chef::Exceptions::User, e.message
- end
+
+ run_dscl("read", "/Users/#{new_resource.username}", "ShadowHashData")
+ break
+ rescue Chef::Exceptions::DsclCommandFailed => e
+ if Time.now < timeout
+ sleep 0.1
+ else
+ raise Chef::Exceptions::User, e.message
end
+
end
end
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 1530243b5d..2c9f53a3e2 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -663,11 +663,11 @@ class Chef
all_props = {}
self.class.state_properties.map do |p|
- begin
- all_props[p.name.to_s] = p.sensitive? ? '"*sensitive value suppressed*"' : value_to_text(p.get(self))
- rescue Chef::Exceptions::ValidationFailed
- # This space left intentionally blank, the property was probably required or had an invalid default.
- end
+
+ all_props[p.name.to_s] = p.sensitive? ? '"*sensitive value suppressed*"' : value_to_text(p.get(self))
+ rescue Chef::Exceptions::ValidationFailed
+ # This space left intentionally blank, the property was probably required or had an invalid default.
+
end
ivars = instance_variables.map(&:to_sym) - HIDDEN_IVARS
diff --git a/lib/chef/resource/chef_vault_secret.rb b/lib/chef/resource/chef_vault_secret.rb
index bbd21ec543..d8a2e89ffe 100644
--- a/lib/chef/resource/chef_vault_secret.rb
+++ b/lib/chef/resource/chef_vault_secret.rb
@@ -73,19 +73,19 @@ class Chef
description: "The Chef environment of the data if storing per environment values."
load_current_value do
- begin
- item = ChefVault::Item.load(data_bag, id)
- raw_data item.raw_data
- clients item.get_clients
- admins item.get_admins
- search item.search
- rescue ChefVault::Exceptions::SecretDecryption
- current_value_does_not_exist!
- rescue ChefVault::Exceptions::KeysNotFound
- current_value_does_not_exist!
- rescue Net::HTTPClientException => e
- current_value_does_not_exist! if e.response_code == "404"
- end
+
+ item = ChefVault::Item.load(data_bag, id)
+ raw_data item.raw_data
+ clients item.get_clients
+ admins item.get_admins
+ search item.search
+ rescue ChefVault::Exceptions::SecretDecryption
+ current_value_does_not_exist!
+ rescue ChefVault::Exceptions::KeysNotFound
+ current_value_does_not_exist!
+ rescue Net::HTTPClientException => e
+ current_value_does_not_exist! if e.response_code == "404"
+
end
action :create do
diff --git a/lib/chef/resource/sysctl.rb b/lib/chef/resource/sysctl.rb
index fcc82d09a2..8b745f709e 100644
--- a/lib/chef/resource/sysctl.rb
+++ b/lib/chef/resource/sysctl.rb
@@ -128,11 +128,11 @@ class Chef
end
load_current_value do
- begin
- value get_sysctl_value(key)
- rescue
- current_value_does_not_exist!
- end
+
+ value get_sysctl_value(key)
+ rescue
+ current_value_does_not_exist!
+
end
action :apply do
diff --git a/lib/chef/run_context/cookbook_compiler.rb b/lib/chef/run_context/cookbook_compiler.rb
index 9d8ea87360..35389931bf 100644
--- a/lib/chef/run_context/cookbook_compiler.rb
+++ b/lib/chef/run_context/cookbook_compiler.rb
@@ -169,17 +169,17 @@ class Chef
def compile_recipes
@events.recipe_load_start(run_list_expansion.recipes.size)
run_list_expansion.recipes.each do |recipe|
- begin
- path = resolve_recipe(recipe)
- @run_context.load_recipe(recipe)
- @events.recipe_file_loaded(path, recipe)
- rescue Chef::Exceptions::RecipeNotFound => e
- @events.recipe_not_found(e)
- raise
- rescue Exception => e
- @events.recipe_file_load_failed(path, e, recipe)
- raise
- end
+
+ path = resolve_recipe(recipe)
+ @run_context.load_recipe(recipe)
+ @events.recipe_file_loaded(path, recipe)
+ rescue Chef::Exceptions::RecipeNotFound => e
+ @events.recipe_not_found(e)
+ raise
+ rescue Exception => e
+ @events.recipe_file_load_failed(path, e, recipe)
+ raise
+
end
@events.recipe_load_complete
end
@@ -231,14 +231,14 @@ class Chef
def load_libraries_from_cookbook(cookbook_name, globs = "**/*.rb")
each_file_in_cookbook_by_segment(cookbook_name, :libraries, globs) do |filename|
- begin
- logger.trace("Loading cookbook #{cookbook_name}'s library file: #{filename}")
- Kernel.require(filename)
- @events.library_file_loaded(filename)
- rescue Exception => e
- @events.library_file_load_failed(filename, e)
- raise
- end
+
+ logger.trace("Loading cookbook #{cookbook_name}'s library file: #{filename}")
+ Kernel.require(filename)
+ @events.library_file_loaded(filename)
+ rescue Exception => e
+ @events.library_file_load_failed(filename, e)
+ raise
+
end
end
diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb
index ce2b014600..806da5922e 100644
--- a/lib/chef/util/diff.rb
+++ b/lib/chef/util/diff.rb
@@ -106,16 +106,16 @@ class Chef
# join them. otherwise, print out the old one.
old_hunk = hunk = nil
diff_data.each do |piece|
- begin
- hunk = ::Diff::LCS::Hunk.new(old_data, new_data, piece, 3, file_length_difference)
- file_length_difference = hunk.file_length_difference
- next unless old_hunk
- next if hunk.merge(old_hunk)
-
- diff_str << old_hunk.diff(:unified) << "\n"
- ensure
- old_hunk = hunk
- end
+
+ hunk = ::Diff::LCS::Hunk.new(old_data, new_data, piece, 3, file_length_difference)
+ file_length_difference = hunk.file_length_difference
+ next unless old_hunk
+ next if hunk.merge(old_hunk)
+
+ diff_str << old_hunk.diff(:unified) << "\n"
+ ensure
+ old_hunk = hunk
+
end
diff_str << old_hunk.diff(:unified) << "\n"
diff_str
diff --git a/lib/chef/win32/file/version_info.rb b/lib/chef/win32/file/version_info.rb
index e24f3cccf9..d1b7c70543 100644
--- a/lib/chef/win32/file/version_info.rb
+++ b/lib/chef/win32/file/version_info.rb
@@ -49,11 +49,11 @@ class Chef
SpecialBuild
}.each do |method|
define_method method do
- begin
- get_version_info_string(method.to_s)
- rescue Chef::Exceptions::Win32APIError
- return nil
- end
+
+ get_version_info_string(method.to_s)
+ rescue Chef::Exceptions::Win32APIError
+ return nil
+
end
end