From f019096eb5916a79af3f5a8ac8e3f1816f1589fb Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 7 Dec 2018 11:15:23 -0800 Subject: change HTTPServerException to HTTPClientException for ruby 2.6 includes backcompat for 2.5 Signed-off-by: Lamont Granquist --- lib/chef/api_client.rb | 2 +- lib/chef/api_client/registration.rb | 2 +- lib/chef/api_client_v1.rb | 8 ++++---- .../chef_fs/file_system/chef_server/acl_entry.rb | 2 +- .../chef_fs/file_system/chef_server/cookbook_dir.rb | 4 ++-- .../chef_fs/file_system/chef_server/cookbook_file.rb | 2 +- .../chef_fs/file_system/chef_server/cookbooks_dir.rb | 2 +- .../chef_fs/file_system/chef_server/data_bag_dir.rb | 2 +- .../chef_fs/file_system/chef_server/data_bags_dir.rb | 4 ++-- .../chef_fs/file_system/chef_server/nodes_dir.rb | 2 +- .../chef_server/organization_invites_entry.rb | 2 +- .../chef_server/organization_members_entry.rb | 2 +- .../chef_fs/file_system/chef_server/policies_dir.rb | 6 +++--- .../file_system/chef_server/policy_group_entry.rb | 4 ++-- .../chef_fs/file_system/chef_server/rest_list_dir.rb | 6 +++--- .../file_system/chef_server/rest_list_entry.rb | 8 ++++---- lib/chef/client.rb | 2 +- lib/chef/config_fetcher.rb | 2 +- lib/chef/cookbook_uploader.rb | 6 +++--- lib/chef/cookbook_version.rb | 2 +- lib/chef/data_bag.rb | 2 +- lib/chef/data_bag_item.rb | 2 +- lib/chef/environment.rb | 2 +- .../cookbook_resolve_error_inspector.rb | 2 +- .../cookbook_sync_error_inspector.rb | 2 +- .../error_inspectors/node_load_error_inspector.rb | 2 +- .../error_inspectors/registration_error_inspector.rb | 2 +- .../run_list_expansion_error_inspector.rb | 2 +- lib/chef/http.rb | 6 +++--- lib/chef/key.rb | 2 +- lib/chef/knife.rb | 2 +- lib/chef/knife/bootstrap/client_builder.rb | 2 +- lib/chef/knife/cookbook_delete.rb | 2 +- lib/chef/knife/cookbook_upload.rb | 2 +- lib/chef/knife/data_bag_create.rb | 2 +- lib/chef/knife/raw.rb | 2 +- lib/chef/knife/search.rb | 2 +- lib/chef/knife/supermarket_share.rb | 2 +- lib/chef/knife/supermarket_unshare.rb | 2 +- lib/chef/mixin/api_version_request_handling.rb | 2 +- lib/chef/monkey_patches/net_http.rb | 6 +++++- lib/chef/node.rb | 8 ++++---- lib/chef/org.rb | 2 +- lib/chef/policy_builder/policyfile.rb | 2 +- lib/chef/provider/apt_repository.rb | 2 +- lib/chef/provider/remote_file/content.rb | 2 +- lib/chef/role.rb | 2 +- lib/chef/run_list/run_list_expansion.rb | 2 +- lib/chef/user.rb | 2 +- lib/chef/user_v1.rb | 8 ++++---- spec/functional/http/simple_spec.rb | 20 ++++++++++---------- spec/integration/knife/client_create_spec.rb | 2 +- spec/integration/knife/client_key_create_spec.rb | 2 +- spec/integration/knife/cookbook_download_spec.rb | 2 +- spec/integration/knife/cookbook_show_spec.rb | 4 ++-- spec/integration/knife/data_bag_create_spec.rb | 2 +- spec/integration/knife/environment_create_spec.rb | 2 +- spec/integration/knife/node_create_spec.rb | 2 +- spec/integration/knife/role_create_spec.rb | 2 +- spec/support/shared/context/client.rb | 2 +- spec/support/shared/unit/api_error_inspector.rb | 10 +++++----- spec/support/shared/unit/api_versioning.rb | 4 ++-- spec/unit/api_client/registration_spec.rb | 2 +- spec/unit/api_client_spec.rb | 4 ++-- spec/unit/api_client_v1_spec.rb | 6 +++--- .../file_system/operation_failed_error_spec.rb | 2 +- spec/unit/client_spec.rb | 2 +- spec/unit/data_bag_item_spec.rb | 2 +- spec/unit/data_bag_spec.rb | 2 +- .../cookbook_resolve_error_inspector_spec.rb | 8 ++++---- .../run_list_expansion_error_inspector_spec.rb | 4 ++-- spec/unit/knife/bootstrap/client_builder_spec.rb | 2 +- spec/unit/knife/cookbook_delete_spec.rb | 6 +++--- spec/unit/knife/data_bag_create_spec.rb | 4 ++-- spec/unit/knife/supermarket_share_spec.rb | 2 +- spec/unit/knife/supermarket_unshare_spec.rb | 6 +++--- spec/unit/knife_spec.rb | 14 +++++++------- spec/unit/mixin/api_version_request_handling_spec.rb | 4 ++-- spec/unit/node_spec.rb | 4 ++-- spec/unit/policy_builder/policyfile_spec.rb | 4 ++-- spec/unit/provider/remote_file/content_spec.rb | 4 ++-- spec/unit/resource_reporter_spec.rb | 14 +++++++------- spec/unit/user_v1_spec.rb | 4 ++-- 83 files changed, 154 insertions(+), 150 deletions(-) diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb index 550aa6bd3f..1bd06652c5 100644 --- a/lib/chef/api_client.rb +++ b/lib/chef/api_client.rb @@ -186,7 +186,7 @@ class Chef # Save this client via the REST API, returns a hash including the private key def save http_api.put("clients/#{name}", { name: name, admin: admin, validator: validator }) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # If that fails, go ahead and try and update it if e.response.code == "404" http_api.post("clients", { name: name, admin: admin, validator: validator }) diff --git a/lib/chef/api_client/registration.rb b/lib/chef/api_client/registration.rb index 6cbb071020..dd214d7812 100644 --- a/lib/chef/api_client/registration.rb +++ b/lib/chef/api_client/registration.rb @@ -93,7 +93,7 @@ class Chef def create_or_update create - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # If create fails because the client exists, attempt to update. This # requires admin privileges. raise unless e.response.code == "409" diff --git a/lib/chef/api_client_v1.rb b/lib/chef/api_client_v1.rb index 8ce06ea780..3a2dafa3a8 100644 --- a/lib/chef/api_client_v1.rb +++ b/lib/chef/api_client_v1.rb @@ -216,7 +216,7 @@ class Chef # Save this client via the REST API, returns a hash including the private key def save update - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # If that fails, go ahead and try and update it if e.response.code == "404" create @@ -235,7 +235,7 @@ class Chef private_key(reregistered_self.private_key) end self - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # if there was a 406 related to versioning, give error explaining that # only API version 0 is supported for reregister command if e.response.code == "406" && e.response["x-ops-server-api-version"] @@ -266,7 +266,7 @@ class Chef begin new_client = chef_rest_v1.put("clients/#{name}", payload) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # rescue API V0 if 406 and the server supports V0 supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS) raise e unless supported_versions && supported_versions.include?(0) @@ -303,7 +303,7 @@ class Chef new_client.delete("chef_key") end - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # rescue API V0 if 406 and the server supports V0 supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS) raise e unless supported_versions && supported_versions.include?(0) 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 3951f1a7e6..98091eaf9a 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 @@ -51,7 +51,7 @@ class Chef 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::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) else diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb index 9b0ea18cd8..a619dc75bf 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb @@ -108,7 +108,7 @@ class Chef rest.delete(api_path) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:delete, self, e, "Timeout deleting: #{e}") - rescue Net::HTTPServerException + rescue Net::HTTPClientException if $!.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) else @@ -182,7 +182,7 @@ class Chef rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" @could_not_get_chef_object = e raise Chef::ChefFS::FileSystem::NotFoundError.new(self, @could_not_get_chef_object) diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb index 6b4657ae6a..a680daacc0 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb @@ -41,7 +41,7 @@ class Chef File.open(tmpfile, "rb") { |f| f.read } rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading #{file[:url]}: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "#{e.message} retrieving #{file[:url]}") rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb index e0eca5f6de..04d48d4e8e 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb @@ -60,7 +60,7 @@ class Chef upload_cookbook(other, options) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e case e.response.code when "409" raise Chef::ChefFS::FileSystem::CookbookFrozenError.new(:write, self, e, "Cookbook #{other.name} is frozen") diff --git a/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb b/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb index ee0ecd3b40..0102ea2844 100644 --- a/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb @@ -56,7 +56,7 @@ class Chef rest.delete(api_path) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:delete, self, e, "Timeout deleting: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) else diff --git a/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb b/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb index 205aa9fd86..6c7dd7b477 100644 --- a/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb @@ -33,7 +33,7 @@ class Chef @children ||= root.get_json(api_path).keys.sort.map { |entry| make_child_entry(entry, true) } rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e, "Timeout getting children: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) else @@ -50,7 +50,7 @@ class Chef rest.post(api_path, { "name" => name }) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e, "Timeout creating child '#{name}': #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "409" raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self, e, "Cannot create #{name} under #{path}: already exists") else diff --git a/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb b/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb index c81e880744..e56c68ffae 100644 --- a/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb @@ -33,7 +33,7 @@ class Chef end rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e, "Timeout retrieving children: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if $!.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) else 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 344a3deecc..02cde95880 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 @@ -46,7 +46,7 @@ class Chef (desired_invites - invites).each do |invite| begin rest.post(api_path, { "user" => invite }) - rescue Net::HTTPServerException => e + 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 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 a780ddd97b..a31922d7c8 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 @@ -45,7 +45,7 @@ class Chef (desired_members - members).each do |member| begin rest.post(api_path, "username" => member) - rescue Net::HTTPServerException => e + 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 diff --git a/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb b/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb index 8259db473d..df589a6cc0 100644 --- a/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb @@ -80,7 +80,7 @@ class Chef end rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e, "Timeout retrieving children: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # 404 = NotFoundError if $!.response.code == "404" # GET /organizations/ORG/policies returned 404, but that just might be because @@ -91,7 +91,7 @@ class Chef root.get_json(parent.api_path) # Return empty list if the organization exists but /policies didn't work [] - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) end @@ -131,7 +131,7 @@ class Chef rest.post("#{api_path}/#{policy_name}/revisions", object) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e, "Timeout creating '#{name}': #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # 404 = NotFoundError if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) diff --git a/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb b/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb index df3d393d35..2a8ebd1f5a 100644 --- a/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb @@ -79,7 +79,7 @@ class Chef get_data = begin rest.get(policy_path) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise "Could not find policy '#{policy_name}'' with revision '#{policy_data["revision_id"]}'' on the server" end @@ -113,7 +113,7 @@ class Chef rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e, "Timeout creating '#{name}': #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # 404 = NotFoundError if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) diff --git a/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb b/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb index 6ba53fab4b..a58a01ae8c 100644 --- a/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb @@ -77,7 +77,7 @@ class Chef end rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e, "Timeout retrieving children: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # 404 = NotFoundError if $!.response.code == "404" @@ -90,7 +90,7 @@ class Chef root.get_json(parent.api_path) # Return empty list if the organization exists but /policies didn't work [] - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) end @@ -133,7 +133,7 @@ class Chef rest.post(api_path, object) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e, "Timeout creating '#{name}': #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # 404 = NotFoundError if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) diff --git a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb index 876ad7282b..9eaae9c73f 100644 --- a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb @@ -72,7 +72,7 @@ class Chef begin @this_object_cache = rest.get(api_path) @exists = true - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" @exists = false else @@ -91,7 +91,7 @@ class Chef rest.delete(api_path) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:delete, self, e, "Timeout deleting: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) else @@ -108,7 +108,7 @@ class Chef @this_object_cache ? JSON.parse(@this_object_cache) : root.get_json(api_path) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if $!.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) else @@ -185,7 +185,7 @@ class Chef rest.put(api_path, object) rescue Timeout::Error => e raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) else diff --git a/lib/chef/client.rb b/lib/chef/client.rb index e668aeee00..15922a5efd 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -552,7 +552,7 @@ class Chef recipe = Chef::Recipe.new(nil, nil, run_context) recipe.from_file(required_recipe_file) run_context - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e case e.response when Net::HTTPNotFound logger.trace("Required Recipe not configured on the server, skipping it") diff --git a/lib/chef/config_fetcher.rb b/lib/chef/config_fetcher.rb index ad03c845ab..d9d100ed00 100644 --- a/lib/chef/config_fetcher.rb +++ b/lib/chef/config_fetcher.rb @@ -39,7 +39,7 @@ class Chef def fetch_remote_config http.get("") - rescue SocketError, SystemCallError, Net::HTTPServerException => error + rescue SocketError, SystemCallError, Net::HTTPClientException => error Chef::Application.fatal!("Cannot fetch config '#{config_location}': '#{error.class}: #{error.message}") end diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb index 5780c61cc9..de367f2455 100644 --- a/lib/chef/cookbook_uploader.rb +++ b/lib/chef/cookbook_uploader.rb @@ -84,7 +84,7 @@ class Chef retries = 0 begin rest.put(sandbox_url, { is_completed: true }) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.message =~ /^400/ && (retries += 1) <= 5 sleep 2 retry @@ -101,7 +101,7 @@ class Chef save_url = opts[:force] ? manifest.force_save_url : manifest.save_url begin rest.put(save_url, manifest) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e case e.response.code when "409" raise Chef::Exceptions::CookbookFrozen, "Version #{cb.version} of cookbook #{cb.name} is frozen. Use --force to override." @@ -128,7 +128,7 @@ class Chef begin rest.put(url, file_contents, headers) checksums_to_upload.delete(checksum) - rescue Net::HTTPServerException, Net::HTTPFatalError, Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError => e + rescue Net::HTTPClientException, Net::HTTPFatalError, Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError => e error_message = "Failed to upload #{file} (#{checksum}) to #{url} : #{e.message}" error_message << "\n#{e.response.body}" if e.respond_to?(:response) Chef::Knife.ui.error(error_message) diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 2ed84e0d9d..8d4eb2e8ab 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -491,7 +491,7 @@ class Chef chef_server_rest.get("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map do |cb| cb["version"] end - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.to_s =~ /^404/ Chef::Log.error("Cannot find a cookbook named #{cookbook_name}") nil diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb index edef971830..35b014905f 100644 --- a/lib/chef/data_bag.rb +++ b/lib/chef/data_bag.rb @@ -153,7 +153,7 @@ class Chef else create end - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise e unless e.response.code == "409" end self diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb index 63b4060baa..9804c271c4 100644 --- a/lib/chef/data_bag_item.rb +++ b/lib/chef/data_bag_item.rb @@ -168,7 +168,7 @@ class Chef else r.put("data/#{data_bag}/#{item_id}", self) end - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise e unless e.response.code == "404" r.post("data/#{data_bag}", self) end diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index c40897d687..1ca035e594 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -275,7 +275,7 @@ class Chef def save begin chef_server_rest.put("environments/#{@name}", self) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise e unless e.response.code == "404" chef_server_rest.post("environments", self) end diff --git a/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb b/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb index a046f1a277..e87ef0da70 100644 --- a/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb @@ -35,7 +35,7 @@ class Chef def add_explanation(error_description) case exception - when Net::HTTPServerException, Net::HTTPFatalError + when Net::HTTPClientException, Net::HTTPFatalError humanize_http_exception(error_description) when EOFError describe_eof_error(error_description) diff --git a/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb b/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb index 3bd9b419fa..6ab2816a57 100644 --- a/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb @@ -41,7 +41,7 @@ class Chef def add_explanation(error_description) case exception - when Net::HTTPServerException, Net::HTTPFatalError + when Net::HTTPClientException, Net::HTTPFatalError humanize_http_exception(error_description) when EOFError describe_eof_error(error_description) diff --git a/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb b/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb index a2f77c8287..7b2ccf0d9a 100644 --- a/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb @@ -40,7 +40,7 @@ class Chef def add_explanation(error_description) case exception - when Net::HTTPServerException, Net::HTTPFatalError + when Net::HTTPClientException, Net::HTTPFatalError humanize_http_exception(error_description) when Chef::Exceptions::PrivateKeyMissing error_description.section("Private Key Not Found:", <<~E) diff --git a/lib/chef/formatters/error_inspectors/registration_error_inspector.rb b/lib/chef/formatters/error_inspectors/registration_error_inspector.rb index 02e8b0d61a..4ca08ca120 100644 --- a/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/registration_error_inspector.rb @@ -23,7 +23,7 @@ class Chef def add_explanation(error_description) case exception - when Net::HTTPServerException, Net::HTTPFatalError + when Net::HTTPClientException, Net::HTTPFatalError humanize_http_exception(error_description) when Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError error_description.section("Network Error:", <<~E) diff --git a/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb b/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb index 9d46465947..ac7304df13 100644 --- a/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb @@ -41,7 +41,7 @@ class Chef Your chef_server_url may be misconfigured, or the network could be down. E - when Net::HTTPServerException, Net::HTTPFatalError + when Net::HTTPClientException, Net::HTTPFatalError humanize_http_exception(error_description) when Chef::Exceptions::MissingRole describe_missing_role(error_description) diff --git a/lib/chef/http.rb b/lib/chef/http.rb index 3f815b9eff..e9f94e6c92 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -152,7 +152,7 @@ class Chef response.error! unless success_response?(response) return_value - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e http_attempts += 1 response = e.response if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0 @@ -190,7 +190,7 @@ class Chef response.error! end tempfile - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e http_attempts += 1 response = e.response if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0 @@ -245,7 +245,7 @@ class Chef end end tempfile - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e http_attempts += 1 response = e.response if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0 diff --git a/lib/chef/key.rb b/lib/chef/key.rb index 6971e84d5f..19ed07f608 100644 --- a/lib/chef/key.rb +++ b/lib/chef/key.rb @@ -187,7 +187,7 @@ class Chef def save create - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "409" update else diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 6e525bdf3d..2bb6169cc9 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -455,7 +455,7 @@ class Chef case e when SystemExit raise # make sure exit passes through. - when Net::HTTPServerException, Net::HTTPFatalError + when Net::HTTPClientException, Net::HTTPFatalError humanize_http_exception(e) when OpenSSL::SSL::SSLError ui.error "Could not establish a secure connection to the server." diff --git a/lib/chef/knife/bootstrap/client_builder.rb b/lib/chef/knife/bootstrap/client_builder.rb index f5c49ab620..5fb0edc31b 100644 --- a/lib/chef/knife/bootstrap/client_builder.rb +++ b/lib/chef/knife/bootstrap/client_builder.rb @@ -187,7 +187,7 @@ class Chef def resource_exists?(relative_path) rest.get(relative_path) true - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise unless e.response.code == "404" false end diff --git a/lib/chef/knife/cookbook_delete.rb b/lib/chef/knife/cookbook_delete.rb index a4f64747c3..3de35d0a72 100644 --- a/lib/chef/knife/cookbook_delete.rb +++ b/lib/chef/knife/cookbook_delete.rb @@ -88,7 +88,7 @@ class Chef @available_versions ||= rest.get("cookbooks/#{@cookbook_name}").map do |name, url_and_version| url_and_version["versions"].map { |url_by_version| url_by_version["version"] } end.flatten - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.to_s =~ /^404/ ui.error("Cannot find a cookbook named #{@cookbook_name} to delete.") nil diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb index ba63e7d0fd..351049c8eb 100644 --- a/lib/chef/knife/cookbook_upload.rb +++ b/lib/chef/knife/cookbook_upload.rb @@ -226,7 +226,7 @@ WARNING def assert_environment_valid! environment - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code.to_s == "404" ui.error "The environment #{config[:environment]} does not exist on the server, aborting." Log.debug(e) diff --git a/lib/chef/knife/data_bag_create.rb b/lib/chef/knife/data_bag_create.rb index 563e931dca..bf90fb81b3 100644 --- a/lib/chef/knife/data_bag_create.rb +++ b/lib/chef/knife/data_bag_create.rb @@ -53,7 +53,7 @@ class Chef begin rest.get("data/#{@data_bag_name}") ui.info("Data bag #{@data_bag_name} already exists") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise unless e.to_s =~ /^404/ # if it doesn't exists, try to create it rest.post("data", { "name" => @data_bag_name }) diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb index a544dcbfdd..a9a757069b 100644 --- a/lib/chef/knife/raw.rb +++ b/lib/chef/knife/raw.rb @@ -112,7 +112,7 @@ class Chef rescue Timeout::Error => e ui.error "Server timeout" exit 1 - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e ui.error "Server responded with error #{e.response.code} \"#{e.response.message}\"" ui.error "Error Body: #{e.response.body}" if e.response.body && e.response.body != "" exit 1 diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index 324c439ddc..168db6da1a 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -109,7 +109,7 @@ class Chef result_items << formatted_item result_count += 1 end - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e msg = Chef::JSONCompat.from_json(e.response.body)["error"].first ui.error("knife search failed: #{msg}") exit 99 diff --git a/lib/chef/knife/supermarket_share.rb b/lib/chef/knife/supermarket_share.rb index a47e16bd8c..bee90a9113 100644 --- a/lib/chef/knife/supermarket_share.rb +++ b/lib/chef/knife/supermarket_share.rb @@ -116,7 +116,7 @@ class Chef data = noauth_rest.get("#{config[:supermarket_site]}/api/v1/cookbooks/#{@name_args[0]}") data["category"] rescue => e - return "Other" if e.kind_of?(Net::HTTPServerException) && e.response.code == "404" + return "Other" if e.kind_of?(Net::HTTPClientException) && e.response.code == "404" ui.fatal("Unable to reach Supermarket: #{e.message}. Increase log verbosity (-VV) for more information.") Chef::Log.trace("\n#{e.backtrace.join("\n")}") exit(1) diff --git a/lib/chef/knife/supermarket_unshare.rb b/lib/chef/knife/supermarket_unshare.rb index e2dfa33b86..98b6fa5789 100644 --- a/lib/chef/knife/supermarket_unshare.rb +++ b/lib/chef/knife/supermarket_unshare.rb @@ -48,7 +48,7 @@ class Chef begin rest.delete "#{config[:supermarket_site]}/api/v1/cookbooks/#{@name_args[0]}" - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise e unless e.message =~ /Forbidden/ ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it." exit 1 diff --git a/lib/chef/mixin/api_version_request_handling.rb b/lib/chef/mixin/api_version_request_handling.rb index 5b9a588cac..a706e10618 100644 --- a/lib/chef/mixin/api_version_request_handling.rb +++ b/lib/chef/mixin/api_version_request_handling.rb @@ -19,7 +19,7 @@ class Chef module Mixin module ApiVersionRequestHandling - # @param exeception [Net::HTTPServerException] may or may not contain the x-ops-server-api-version header + # @param exeception [Net::HTTPClientException] may or may not contain the x-ops-server-api-version header # supported_client_versions: # @param supported_client_versions [Array] The API versions the client supports. # diff --git a/lib/chef/monkey_patches/net_http.rb b/lib/chef/monkey_patches/net_http.rb index 15ccf0fff5..775568639b 100644 --- a/lib/chef/monkey_patches/net_http.rb +++ b/lib/chef/monkey_patches/net_http.rb @@ -5,6 +5,10 @@ module ChefNetHTTPExceptionExtensions attr_accessor :chef_rest_request end +unless defined?(Net::HTTPClientException) + Net::HTTPClientException = Net::HTTPServerException +end + require "net/http" module Net class HTTPError @@ -13,7 +17,7 @@ module Net class HTTPRetriableError include ChefNetHTTPExceptionExtensions end - class HTTPServerException + class HTTPClientException include ChefNetHTTPExceptionExtensions end class HTTPFatalError diff --git a/lib/chef/node.rb b/lib/chef/node.rb index c31fc99279..87418b5732 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -575,7 +575,7 @@ class Chef def self.find_or_create(node_name) load(node_name) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise unless e.response.code == "404" node = build(node_name) node.create @@ -608,7 +608,7 @@ class Chef else chef_server_rest.put("nodes/#{name}", data_for_save) end - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "404" chef_server_rest.post("nodes", data_for_save) else @@ -622,7 +622,7 @@ class Chef def create chef_server_rest.post("nodes", data_for_save) self - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # Chef Server before 12.3 rejects node JSON with 'policy_name' or # 'policy_group' keys, but 'policy_name' will be detected first. # Backcompat can be removed in 13.0 @@ -655,7 +655,7 @@ class Chef trimmed_data = data_for_save_without_policyfile_attrs chef_server_rest.put("nodes/#{name}", trimmed_data) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise e unless e.response.code == "404" chef_server_rest.post("nodes", trimmed_data) end diff --git a/lib/chef/org.rb b/lib/chef/org.rb index afc5cf148d..28702bd314 100644 --- a/lib/chef/org.rb +++ b/lib/chef/org.rb @@ -92,7 +92,7 @@ class Chef def save create - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "409" update else diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb index dd1dc40274..3e7462f0ed 100644 --- a/lib/chef/policy_builder/policyfile.rb +++ b/lib/chef/policy_builder/policyfile.rb @@ -311,7 +311,7 @@ class Chef # @api private def policy @policy ||= api_service.get(policyfile_location) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise ConfigurationError, "Error loading policyfile from `#{policyfile_location}': #{e.class} - #{e.message}" end diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb index 45cc40508c..96ffb5831f 100644 --- a/lib/chef/provider/apt_repository.rb +++ b/lib/chef/provider/apt_repository.rb @@ -271,7 +271,7 @@ class Chef url = "https://launchpad.net/api/1.0/~#{owner}/+archive/#{repo}" key_id = Chef::HTTP::Simple.new(url).get("signing_key_fingerprint").delete('"') install_key_from_keyserver(key_id, "keyserver.ubuntu.com") - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise "Could not access Launchpad ppa API: #{e.message}" end diff --git a/lib/chef/provider/remote_file/content.rb b/lib/chef/provider/remote_file/content.rb index 4cf2c32287..b5f42749e7 100644 --- a/lib/chef/provider/remote_file/content.rb +++ b/lib/chef/provider/remote_file/content.rb @@ -54,7 +54,7 @@ class Chef as_uri(source) end raw_file = grab_file_from_uri(uri) - rescue SocketError, Errno::ECONNREFUSED, Errno::ENOENT, Errno::EACCES, Timeout::Error, Net::HTTPServerException, Net::HTTPFatalError, Net::FTPError, Errno::ETIMEDOUT => e + rescue SocketError, Errno::ECONNREFUSED, Errno::ENOENT, Errno::EACCES, Timeout::Error, Net::HTTPClientException, Net::HTTPFatalError, Net::FTPError, Errno::ETIMEDOUT => e logger.warn("#{@new_resource} cannot be downloaded from #{source}: #{e}") if source = sources.shift logger.info("#{@new_resource} trying to download from another mirror") diff --git a/lib/chef/role.rb b/lib/chef/role.rb index fc9a383a1f..31318fbfe3 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -224,7 +224,7 @@ class Chef def save begin chef_server_rest.put("roles/#{@name}", self) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e raise e unless e.response.code == "404" chef_server_rest.post("roles", self) end diff --git a/lib/chef/run_list/run_list_expansion.rb b/lib/chef/run_list/run_list_expansion.rb index a679eceba5..97422bee16 100644 --- a/lib/chef/run_list/run_list_expansion.rb +++ b/lib/chef/run_list/run_list_expansion.rb @@ -219,7 +219,7 @@ class Chef def fetch_role(name, included_by) Chef::Role.from_hash(rest.get("roles/#{name}")) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.message == '404 "Not Found"' role_not_found(name, included_by) else diff --git a/lib/chef/user.rb b/lib/chef/user.rb index f44d38c2d5..9b2c5bc8f0 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -115,7 +115,7 @@ class Chef def save(new_key = false) create - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "409" update(new_key) else diff --git a/lib/chef/user_v1.rb b/lib/chef/user_v1.rb index 949f5b0909..2f35ec8be0 100644 --- a/lib/chef/user_v1.rb +++ b/lib/chef/user_v1.rb @@ -164,7 +164,7 @@ class Chef new_user["public_key"] = new_user["chef_key"]["public_key"] new_user.delete("chef_key") end - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # rescue API V0 if 406 and the server supports V0 supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS) raise e unless supported_versions && supported_versions.include?(0) @@ -200,7 +200,7 @@ class Chef payload[:private_key] = new_key if new_key updated_user = chef_root_rest_v1.put("users/#{username}", payload) - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "400" # if a 400 is returned but the error message matches the error related to private / public key fields, try V0 # else, raise the 400 @@ -220,7 +220,7 @@ class Chef def save(new_key = false) create - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e if e.response.code == "409" update(new_key) else @@ -235,7 +235,7 @@ class Chef reregistered_self = chef_root_rest_v0.put("users/#{username}", payload) private_key(reregistered_self["private_key"]) # only V0 supported for reregister - rescue Net::HTTPServerException => e + rescue Net::HTTPClientException => e # if there was a 406 related to versioning, give error explaining that # only API version 0 is supported for reregister command if e.response.code == "406" && e.response["x-ops-server-api-version"] diff --git a/spec/functional/http/simple_spec.rb b/spec/functional/http/simple_spec.rb index e835bb0c79..313fed064b 100644 --- a/spec/functional/http/simple_spec.rb +++ b/spec/functional/http/simple_spec.rb @@ -61,27 +61,27 @@ describe Chef::HTTP::Simple do end shared_examples_for "an endpoint that 403s" do - it "fails with a Net::HTTPServerException for a streaming request" do - expect { http_client.streaming_request(source) }.to raise_error(Net::HTTPServerException) + it "fails with a Net::HTTPClientException for a streaming request" do + expect { http_client.streaming_request(source) }.to raise_error(Net::HTTPClientException) end - it "fails with a Net::HTTPServerException for a GET request" do - expect { http_client.get(source) }.to raise_error(Net::HTTPServerException) + it "fails with a Net::HTTPClientException for a GET request" do + expect { http_client.get(source) }.to raise_error(Net::HTTPClientException) end end # see CHEF-5100 shared_examples_for "a 403 after a successful request when reusing the request object" do - it "fails with a Net::HTTPServerException for a streaming request" do + it "fails with a Net::HTTPClientException for a streaming request" do tempfile = http_client.streaming_request(source) tempfile.close expect(Digest::MD5.hexdigest(binread(tempfile.path))).to eq(Digest::MD5.hexdigest(expected_content)) - expect { http_client.streaming_request(source2) }.to raise_error(Net::HTTPServerException) + expect { http_client.streaming_request(source2) }.to raise_error(Net::HTTPClientException) end - it "fails with a Net::HTTPServerException for a GET request" do + it "fails with a Net::HTTPClientException for a GET request" do expect(Digest::MD5.hexdigest(http_client.get(source))).to eq(Digest::MD5.hexdigest(expected_content)) - expect { http_client.get(source2) }.to raise_error(Net::HTTPServerException) + expect { http_client.get(source2) }.to raise_error(Net::HTTPClientException) end end @@ -120,7 +120,7 @@ describe Chef::HTTP::Simple do it "Logs the request and response and bodies for 400 response" do expect do http_client.get("http://localhost:9000/bad_request") - end.to raise_error(Net::HTTPServerException) + end.to raise_error(Net::HTTPClientException) expect(@debug_log).to match(/400/) expect(@debug_log).to match(/HTTP Request Header Data/) expect(@debug_log).to match(/HTTP Status and Header Data/) @@ -133,7 +133,7 @@ describe Chef::HTTP::Simple do it "Logs the request and response and bodies for 400 POST response" do expect do http_client.post("http://localhost:9000/bad_request", "hithere") - end.to raise_error(Net::HTTPServerException) + end.to raise_error(Net::HTTPClientException) expect(@debug_log).to match(/400/) expect(@debug_log).to match(/HTTP Request Header Data/) expect(@debug_log).to match(/HTTP Status and Header Data/) diff --git a/spec/integration/knife/client_create_spec.rb b/spec/integration/knife/client_create_spec.rb index d24755a48a..86609a63cd 100644 --- a/spec/integration/knife/client_create_spec.rb +++ b/spec/integration/knife/client_create_spec.rb @@ -44,7 +44,7 @@ EOM it "refuses to add an existing client" do pending "Knife client create must not blindly overwrite an existing client" knife("client create -k bah").should_succeed stderr: out - expect { knife("client create -k bah") }.to raise_error(Net::HTTPServerException) + expect { knife("client create -k bah") }.to raise_error(Net::HTTPClientException) end it "saves the private key to a file" do diff --git a/spec/integration/knife/client_key_create_spec.rb b/spec/integration/knife/client_key_create_spec.rb index b588afbe50..7ccec8bffd 100644 --- a/spec/integration/knife/client_key_create_spec.rb +++ b/spec/integration/knife/client_key_create_spec.rb @@ -43,7 +43,7 @@ describe "knife client key create", :workstation do it "refuses to add an already existing key" do knife("client key create -k new bah") - expect { knife("client key create -k new bah") }.to raise_error(Net::HTTPServerException) + expect { knife("client key create -k new bah") }.to raise_error(Net::HTTPClientException) end it "saves the private key to a file" do diff --git a/spec/integration/knife/cookbook_download_spec.rb b/spec/integration/knife/cookbook_download_spec.rb index 57174a1548..2dbf9e5ae5 100644 --- a/spec/integration/knife/cookbook_download_spec.rb +++ b/spec/integration/knife/cookbook_download_spec.rb @@ -49,7 +49,7 @@ EOM end it "knife cookbook download with an unknown version raises an error" do - expect { knife("cookbook download -d #{tmpdir} x 1.0.0") }.to raise_error(Net::HTTPServerException) + expect { knife("cookbook download -d #{tmpdir} x 1.0.0") }.to raise_error(Net::HTTPClientException) end end diff --git a/spec/integration/knife/cookbook_show_spec.rb b/spec/integration/knife/cookbook_show_spec.rb index fe7e6fa930..a8e87204e4 100644 --- a/spec/integration/knife/cookbook_show_spec.rb +++ b/spec/integration/knife/cookbook_show_spec.rb @@ -138,11 +138,11 @@ EOM end it "knife cookbook show with a non-existent version displays an error" do - expect { knife("cookbook show x 1.0.1") }.to raise_error(Net::HTTPServerException) + expect { knife("cookbook show x 1.0.1") }.to raise_error(Net::HTTPClientException) end it "knife cookbook show with a non-existent cookbook displays an error" do - expect { knife("cookbook show y") }.to raise_error(Net::HTTPServerException) + expect { knife("cookbook show y") }.to raise_error(Net::HTTPClientException) end end end diff --git a/spec/integration/knife/data_bag_create_spec.rb b/spec/integration/knife/data_bag_create_spec.rb index dc61d55fd5..5ee7a2f00d 100644 --- a/spec/integration/knife/data_bag_create_spec.rb +++ b/spec/integration/knife/data_bag_create_spec.rb @@ -49,7 +49,7 @@ describe "knife data bag create", :workstation do it "fails to add an existing item" do knife("data bag create foo bar").should_succeed stdout: out, stderr: err - expect { knife("data bag create foo bar") }.to raise_error(Net::HTTPServerException) + expect { knife("data bag create foo bar") }.to raise_error(Net::HTTPClientException) end end end diff --git a/spec/integration/knife/environment_create_spec.rb b/spec/integration/knife/environment_create_spec.rb index 03fd4e63f7..2647a08f8b 100644 --- a/spec/integration/knife/environment_create_spec.rb +++ b/spec/integration/knife/environment_create_spec.rb @@ -33,7 +33,7 @@ describe "knife environment create", :workstation do it "refuses to add an existing environment" do pending "Knife environment create must not blindly overwrite an existing environment" knife("environment create bah").should_succeed out - expect { knife("environment create bah") }.to raise_error(Net::HTTPServerException) + expect { knife("environment create bah") }.to raise_error(Net::HTTPClientException) end end diff --git a/spec/integration/knife/node_create_spec.rb b/spec/integration/knife/node_create_spec.rb index 93a2f9ce6f..36778b3dfa 100644 --- a/spec/integration/knife/node_create_spec.rb +++ b/spec/integration/knife/node_create_spec.rb @@ -39,7 +39,7 @@ describe "knife node create", :workstation do it "refuses to add an existing node" do pending "Knife node create must not blindly overwrite an existing node" knife("node create bah").should_succeed out - expect { knife("node create bah") }.to raise_error(Net::HTTPServerException) + expect { knife("node create bah") }.to raise_error(Net::HTTPClientException) end end diff --git a/spec/integration/knife/role_create_spec.rb b/spec/integration/knife/role_create_spec.rb index 941eaf5cb6..54ade9de09 100644 --- a/spec/integration/knife/role_create_spec.rb +++ b/spec/integration/knife/role_create_spec.rb @@ -33,7 +33,7 @@ describe "knife role create", :workstation do it "refuses to add an existing role" do pending "Knife role create must not blindly overwrite an existing role" knife("role create bah").should_succeed out - expect { knife("role create bah") }.to raise_error(Net::HTTPServerException) + expect { knife("role create bah") }.to raise_error(Net::HTTPClientException) end end diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb index 0054058d0f..d6c49c896b 100644 --- a/spec/support/shared/context/client.rb +++ b/spec/support/shared/context/client.rb @@ -142,7 +142,7 @@ shared_context "a client run" do def stub_for_required_recipe response = Net::HTTPNotFound.new("1.1", "404", "Not Found") - exception = Net::HTTPServerException.new('404 "Not Found"', response) + exception = Net::HTTPClientException.new('404 "Not Found"', response) expect(http_node_load).to receive(:get).with("required_recipe").and_raise(exception) end diff --git a/spec/support/shared/unit/api_error_inspector.rb b/spec/support/shared/unit/api_error_inspector.rb index 15c122e3dc..92ed9fcb99 100644 --- a/spec/support/shared/unit/api_error_inspector.rb +++ b/spec/support/shared/unit/api_error_inspector.rb @@ -71,7 +71,7 @@ shared_examples_for "an api error inspector" do @response_body = "synchronize the clock on your host" @response = Net::HTTPUnauthorized.new("1.1", "401", "(response) unauthorized") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) unauthorized", @response) + @exception = Net::HTTPClientException.new("(exception) unauthorized", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) end @@ -87,7 +87,7 @@ shared_examples_for "an api error inspector" do @response_body = "check your key and node name" @response = Net::HTTPUnauthorized.new("1.1", "401", "(response) unauthorized") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) unauthorized", @response) + @exception = Net::HTTPClientException.new("(exception) unauthorized", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) end @@ -103,7 +103,7 @@ shared_examples_for "an api error inspector" do @response_body = "forbidden" @response = Net::HTTPForbidden.new("1.1", "403", "(response) forbidden") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) forbidden", @response) + @exception = Net::HTTPClientException.new("(exception) forbidden", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) end @@ -119,7 +119,7 @@ shared_examples_for "an api error inspector" do @response_body = "didn't like your data" @response = Net::HTTPBadRequest.new("1.1", "400", "(response) bad request") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) bad request", @response) + @exception = Net::HTTPClientException.new("(exception) bad request", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) end @@ -135,7 +135,7 @@ shared_examples_for "an api error inspector" do @response_body = "probably caused by a redirect to a get" @response = Net::HTTPNotFound.new("1.1", "404", "(response) not found") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) not found", @response) + @exception = Net::HTTPClientException.new("(exception) not found", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) end diff --git a/spec/support/shared/unit/api_versioning.rb b/spec/support/shared/unit/api_versioning.rb index 9c179efa82..55718971ef 100644 --- a/spec/support/shared/unit/api_versioning.rb +++ b/spec/support/shared/unit/api_versioning.rb @@ -20,7 +20,7 @@ require "chef/exceptions" shared_examples_for "version handling" do let(:response_406) { OpenStruct.new(code: "406") } - let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) } + let(:exception_406) { Net::HTTPClientException.new("406 Not Acceptable", response_406) } before do allow(rest_v1).to receive(http_verb).and_raise(exception_406) @@ -39,7 +39,7 @@ end # version handling shared_examples_for "user and client reregister" do let(:response_406) { OpenStruct.new(code: "406") } - let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) } + let(:exception_406) { Net::HTTPClientException.new("406 Not Acceptable", response_406) } let(:generic_exception) { Exception.new } let(:min_version) { "2" } let(:max_version) { "5" } diff --git a/spec/unit/api_client/registration_spec.rb b/spec/unit/api_client/registration_spec.rb index 407c2c9f07..6fd1d4d0e1 100644 --- a/spec/unit/api_client/registration_spec.rb +++ b/spec/unit/api_client/registration_spec.rb @@ -61,7 +61,7 @@ describe Chef::ApiClient::Registration do end let(:response_409) { Net::HTTPConflict.new("1.1", "409", "Conflict") } - let(:exception_409) { Net::HTTPServerException.new("409 conflict", response_409) } + let(:exception_409) { Net::HTTPClientException.new("409 conflict", response_409) } let(:generated_private_key_pem) { IO.read(File.expand_path("ssl/private_key.pem", CHEF_SPEC_DATA)) } let(:generated_private_key) { OpenSSL::PKey::RSA.new(generated_private_key_pem) } diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index e83906e712..e6b2eec820 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -280,13 +280,13 @@ describe Chef::ApiClient do context "and the client does not exist on the server" do before do @a_404_response = Net::HTTPNotFound.new("404 not found and such", nil, nil) - @a_404_exception = Net::HTTPServerException.new("404 not found exception", @a_404_response) + @a_404_exception = Net::HTTPClientException.new("404 not found exception", @a_404_response) expect(@http_client).to receive(:get).with("clients/lost-my-key").and_raise(@a_404_exception) end it "raises a 404 error" do - expect { Chef::ApiClient.reregister("lost-my-key") }.to raise_error(Net::HTTPServerException) + expect { Chef::ApiClient.reregister("lost-my-key") }.to raise_error(Net::HTTPClientException) end end diff --git a/spec/unit/api_client_v1_spec.rb b/spec/unit/api_client_v1_spec.rb index 802384534b..6c4e7fe188 100644 --- a/spec/unit/api_client_v1_spec.rb +++ b/spec/unit/api_client_v1_spec.rb @@ -312,20 +312,20 @@ describe Chef::ApiClientV1 do context "and the client does not exist on the server" do before do @a_404_response = Net::HTTPNotFound.new("404 not found and such", nil, nil) - @a_404_exception = Net::HTTPServerException.new("404 not found exception", @a_404_response) + @a_404_exception = Net::HTTPClientException.new("404 not found exception", @a_404_response) expect(@http_client).to receive(:get).with("clients/lost-my-key").and_raise(@a_404_exception) end it "raises a 404 error" do - expect { Chef::ApiClientV1.reregister("lost-my-key") }.to raise_error(Net::HTTPServerException) + expect { Chef::ApiClientV1.reregister("lost-my-key") }.to raise_error(Net::HTTPClientException) end end end describe "Versioned API Interactions" do let(:response_406) { OpenStruct.new(code: "406") } - let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) } + let(:exception_406) { Net::HTTPClientException.new("406 Not Acceptable", response_406) } let(:payload) do { name: "some_name", diff --git a/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb b/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb index acdbe35c45..661994337b 100644 --- a/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +++ b/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb @@ -29,7 +29,7 @@ describe Chef::ChefFS::FileSystem::OperationFailedError do response_body = '{"error":["Invalid key test in request body"]}' allow(@response).to receive(:code).and_return("400") allow(@response).to receive(:body).and_return(response_body) - exception = Net::HTTPServerException.new("(exception) unauthorized", @response) + exception = Net::HTTPClientException.new("(exception) unauthorized", @response) expect do raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, exception), error_message end.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, "#{error_message} cause: #{response_body}") diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index acb5fb7997..9e20058846 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -441,7 +441,7 @@ EOM context "when required_recipe returns 404" do let(:http_response) { Net::HTTPNotFound.new("1.1", "404", "Not Found") } - let(:http_exception) { Net::HTTPServerException.new('404 "Not Found"', http_response) } + let(:http_exception) { Net::HTTPClientException.new('404 "Not Found"', http_response) } before(:each) do expect(rest).to receive(:get).with("required_recipe").and_raise(http_exception) diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb index 3ebbf5c9a0..70fcd7041e 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -298,7 +298,7 @@ describe Chef::DataBagItem do it "should create if the item is not found" do exception = double("404 error", code: "404") - expect(server).to receive(:put).and_raise(Net::HTTPServerException.new("foo", exception)) + expect(server).to receive(:put).and_raise(Net::HTTPClientException.new("foo", exception)) expect(server).to receive(:post).with("data/books", data_bag_item) data_bag_item.save end diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index f20148de72..388c35232f 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -89,7 +89,7 @@ describe Chef::DataBag do it "should silently proceed when the data bag already exists" do exception = double("409 error", code: "409") - expect(@rest).to receive(:post).and_raise(Net::HTTPServerException.new("foo", exception)) + expect(@rest).to receive(:post).and_raise(Net::HTTPClientException.new("foo", exception)) @data_bag.save end diff --git a/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb index 07643385b4..35ae5378cf 100644 --- a/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb @@ -35,7 +35,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = %q({"error": [{"message": "gtfo"}]) @response = Net::HTTPForbidden.new("1.1", "403", "(response) forbidden") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) forbidden", @response) + @exception = Net::HTTPClientException.new("(exception) forbidden", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @inspector.add_explanation(@description) @@ -56,7 +56,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[\"{\\\"non_existent_cookbooks\\\":[\\\"apache2\\\"],\\\"cookbooks_with_no_versions\\\":[\\\"users\\\"],\\\"message\\\":\\\"Run list contains invalid items: no such cookbook nope.\\\"}\"]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) + @exception = Net::HTTPClientException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @inspector.add_explanation(@description) @@ -84,7 +84,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[{\"non_existent_cookbooks\":[],\"cookbooks_with_no_versions\":[],\"message\":\"unable to solve dependencies in alotted time.\"}]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) + @exception = Net::HTTPClientException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @inspector.add_explanation(@description) @@ -107,7 +107,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[{\"non_existent_cookbooks\":[\"apache2\"],\"cookbooks_with_no_versions\":[\"users\"],\"message\":\"Run list contains invalid items: no such cookbook nope.\"}]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) + @exception = Net::HTTPClientException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @inspector.add_explanation(@description) diff --git a/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb index 70cf96f7c9..57f1f53f2c 100644 --- a/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb @@ -55,7 +55,7 @@ describe Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector do @response_body = "forbidden" @response = Net::HTTPForbidden.new("1.1", "403", "(response) forbidden") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) forbidden", @response) + @exception = Net::HTTPClientException.new("(exception) forbidden", @response) @inspector = Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector.new(@node, @exception) allow(@inspector).to receive(:config).and_return(node_name: "unit-test.example.com") @@ -73,7 +73,7 @@ describe Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector do @response_body = "check your key and node name" @response = Net::HTTPUnauthorized.new("1.1", "401", "(response) unauthorized") allow(@response).to receive(:body).and_return(@response_body) - @exception = Net::HTTPServerException.new("(exception) unauthorized", @response) + @exception = Net::HTTPClientException.new("(exception) unauthorized", @response) @inspector = Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector.new(@node, @exception) allow(@inspector).to receive(:config).and_return(node_name: "unit-test.example.com", diff --git a/spec/unit/knife/bootstrap/client_builder_spec.rb b/spec/unit/knife/bootstrap/client_builder_spec.rb index f259002b20..6a9ec1dc34 100644 --- a/spec/unit/knife/bootstrap/client_builder_spec.rb +++ b/spec/unit/knife/bootstrap/client_builder_spec.rb @@ -42,7 +42,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do context "#sanity_check!" do let(:response_404) { OpenStruct.new(code: "404") } - let(:exception_404) { Net::HTTPServerException.new("404 not found", response_404) } + let(:exception_404) { Net::HTTPClientException.new("404 not found", response_404) } context "in cases where the prompting fails" do before do diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb index 7277b63c28..f65a26c455 100644 --- a/spec/unit/knife/cookbook_delete_spec.rb +++ b/spec/unit/knife/cookbook_delete_spec.rb @@ -139,15 +139,15 @@ describe Chef::Knife::CookbookDelete do end it "should raise if an error other than HTTP 404 is returned" do - exception = Net::HTTPServerException.new("500 Internal Server Error", "500") + exception = Net::HTTPClientException.new("500 Internal Server Error", "500") expect(@rest_mock).to receive(:get).and_raise(exception) - expect { @knife.available_versions }.to raise_error Net::HTTPServerException + expect { @knife.available_versions }.to raise_error Net::HTTPClientException end describe "if the cookbook can't be found" do before(:each) do expect(@rest_mock).to receive(:get) - .and_raise(Net::HTTPServerException.new("404 Not Found", "404")) + .and_raise(Net::HTTPClientException.new("404 Not Found", "404")) end it "should print an error" do diff --git a/spec/unit/knife/data_bag_create_spec.rb b/spec/unit/knife/data_bag_create_spec.rb index 6624fb70ab..d12f3398f3 100644 --- a/spec/unit/knife/data_bag_create_spec.rb +++ b/spec/unit/knife/data_bag_create_spec.rb @@ -63,7 +63,7 @@ describe Chef::Knife::DataBagCreate do exception = double("404 error", code: "404") allow(rest).to receive(:get) .with("data/#{bag_name}") - .and_raise(Net::HTTPServerException.new("404", exception)) + .and_raise(Net::HTTPClientException.new("404", exception)) end it "tries to create a data bag with an invalid name when given one argument" do @@ -86,7 +86,7 @@ describe Chef::Knife::DataBagCreate do %w{node role client environment}.each do |name| allow(rest).to receive(:get) .with("data/sudoing_#{name}_admins") - .and_raise(Net::HTTPServerException.new("404", exception)) + .and_raise(Net::HTTPClientException.new("404", exception)) end end diff --git a/spec/unit/knife/supermarket_share_spec.rb b/spec/unit/knife/supermarket_share_spec.rb index dde58775f4..6601cdcd31 100644 --- a/spec/unit/knife/supermarket_share_spec.rb +++ b/spec/unit/knife/supermarket_share_spec.rb @@ -85,7 +85,7 @@ describe Chef::Knife::SupermarketShare do it "should use a default category when given only 1 argument and cannot determine category" do @knife.name_args = ["cookbook_name"] - expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Net::HTTPServerException.new("404 Not Found", OpenStruct.new(code: "404")) } + expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Net::HTTPClientException.new("404 Not Found", OpenStruct.new(code: "404")) } expect(@knife).to receive(:do_upload) expect { @knife.run }.to_not raise_error end diff --git a/spec/unit/knife/supermarket_unshare_spec.rb b/spec/unit/knife/supermarket_unshare_spec.rb index 206717e211..5976297fb6 100644 --- a/spec/unit/knife/supermarket_unshare_spec.rb +++ b/spec/unit/knife/supermarket_unshare_spec.rb @@ -57,15 +57,15 @@ describe Chef::Knife::SupermarketUnshare do it "should log an error and exit when forbidden" do exception = double('403 "Forbidden"', code: "403") - allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception)) + allow(@rest).to receive(:delete).and_raise(Net::HTTPClientException.new('403 "Forbidden"', exception)) expect(@knife.ui).to receive(:error) expect { @knife.run }.to raise_error(SystemExit) end it "should re-raise any non-forbidden errors on delete" do exception = double('500 "Application Error"', code: "500") - allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception)) - expect { @knife.run }.to raise_error(Net::HTTPServerException) + allow(@rest).to receive(:delete).and_raise(Net::HTTPClientException.new('500 "Application Error"', exception)) + expect { @knife.run }.to raise_error(Net::HTTPClientException) end it "should log a success message" do diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index c091286077..67251b2cd9 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -424,7 +424,7 @@ describe Chef::Knife do response = Net::HTTPUnauthorized.new("1.1", "401", "Unauthorized") response.instance_variable_set(:@read, true) # I hate you, net/http. allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "y u no syncronize your clock?")) - allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("401 Unauthorized", response)) + allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("401 Unauthorized", response)) knife.run_with_pretty_exceptions expect(stderr.string).to match(/ERROR: Failed to authenticate to/) expect(stderr.string).to match(/Response: y u no syncronize your clock\?/) @@ -434,7 +434,7 @@ describe Chef::Knife do response = Net::HTTPForbidden.new("1.1", "403", "Forbidden") response.instance_variable_set(:@read, true) # I hate you, net/http. allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "y u no administrator")) - allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("403 Forbidden", response)) + allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("403 Forbidden", response)) allow(knife).to receive(:username).and_return("sadpanda") knife.run_with_pretty_exceptions expect(stderr.string).to match(%r{ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action}) @@ -454,7 +454,7 @@ describe Chef::Knife do response = Net::HTTPForbidden.new("1.1", "403", "Forbidden") response.instance_variable_set(:@read, true) allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "y u no administrator")) - allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("403 Forbidden", response)) + allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("403 Forbidden", response)) allow(knife).to receive(:username).and_return("sadpanda") knife.run_with_pretty_exceptions expect(stderr.string).to match(%r{ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action}) @@ -467,7 +467,7 @@ describe Chef::Knife do response = Net::HTTPBadRequest.new("1.1", "400", "Bad Request") response.instance_variable_set(:@read, true) # I hate you, net/http. allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "y u search wrong")) - allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("400 Bad Request", response)) + allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("400 Bad Request", response)) knife.run_with_pretty_exceptions expect(stderr.string).to match(%r{ERROR: The data in your request was invalid}) expect(stderr.string).to match(%r{Response: y u search wrong}) @@ -477,7 +477,7 @@ describe Chef::Knife do response = Net::HTTPNotFound.new("1.1", "404", "Not Found") response.instance_variable_set(:@read, true) # I hate you, net/http. allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "nothing to see here")) - allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("404 Not Found", response)) + allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("404 Not Found", response)) knife.run_with_pretty_exceptions expect(stderr.string).to match(%r{ERROR: The object you are looking for could not be found}) expect(stderr.string).to match(%r{Response: nothing to see here}) @@ -491,7 +491,7 @@ describe Chef::Knife do response["x-ops-server-api-version"] = Chef::JSONCompat.to_json(min_version: "0", max_version: "1", request_version: "10000000") allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "sad trombone")) - allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("406 Not Acceptable", response)) + allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("406 Not Acceptable", response)) knife.run_with_pretty_exceptions expect(stderr.string).to include("The request that Knife sent was using API version 10000000") @@ -533,7 +533,7 @@ describe Chef::Knife do response = Net::HTTPPaymentRequired.new("1.1", "402", "Payment Required") response.instance_variable_set(:@read, true) # I hate you, net/http. allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "nobugfixtillyoubuy")) - allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("402 Payment Required", response)) + allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("402 Payment Required", response)) knife.run_with_pretty_exceptions expect(stderr.string).to match(%r{ERROR: Payment Required}) expect(stderr.string).to match(%r{Response: nobugfixtillyoubuy}) diff --git a/spec/unit/mixin/api_version_request_handling_spec.rb b/spec/unit/mixin/api_version_request_handling_spec.rb index cabc85439c..f3b3fa14ab 100644 --- a/spec/unit/mixin/api_version_request_handling_spec.rb +++ b/spec/unit/mixin/api_version_request_handling_spec.rb @@ -27,7 +27,7 @@ describe Chef::Mixin::ApiVersionRequestHandling do context "when the response code is not 406" do let(:response) { OpenStruct.new(code: "405") } - let(:exception) { Net::HTTPServerException.new("405 Something Else", response) } + let(:exception) { Net::HTTPClientException.new("405 Something Else", response) } it "returns nil" do expect(object.server_client_api_version_intersection(exception, default_supported_client_versions)) @@ -38,7 +38,7 @@ describe Chef::Mixin::ApiVersionRequestHandling do context "when the response code is 406" do let(:response) { OpenStruct.new(code: "406") } - let(:exception) { Net::HTTPServerException.new("406 Not Acceptable", response) } + let(:exception) { Net::HTTPClientException.new("406 Not Acceptable", response) } context "when x-ops-server-api-version header does not exist" do it "returns nil" do diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index ff912ee7a6..4c056ca349 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -53,7 +53,7 @@ describe Chef::Node do describe "when the node does not exist on the server" do before do response = OpenStruct.new(code: "404") - exception = Net::HTTPServerException.new("404 not found", response) + exception = Net::HTTPClientException.new("404 not found", response) allow(Chef::Node).to receive(:load).and_raise(exception) node.name("created-node") end @@ -1447,7 +1447,7 @@ describe Chef::Node do node.name("monkey") allow(node).to receive(:data_for_save).and_return({}) exception = double("404 error", code: "404") - expect(@rest).to receive(:put).and_raise(Net::HTTPServerException.new("foo", exception)) + expect(@rest).to receive(:put).and_raise(Net::HTTPClientException.new("foo", exception)) expect(@rest).to receive(:post).with("nodes", {}) node.save end diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index ab2fdecfe7..f22e2a74b3 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -218,7 +218,7 @@ describe Chef::PolicyBuilder::Policyfile do end context "when the deployment group cannot be loaded" do - let(:error404) { Net::HTTPServerException.new("404 message", :body) } + let(:error404) { Net::HTTPClientException.new("404 message", :body) } before do expect(api_service).to receive(:get) @@ -738,7 +738,7 @@ describe Chef::PolicyBuilder::Policyfile do shared_examples "fetching cookbooks when they don't exist" do context "and a cookbook is missing" do - let(:error404) { Net::HTTPServerException.new("404 message", :body) } + let(:error404) { Net::HTTPClientException.new("404 message", :body) } before do policy_builder.finish_load_node(node) diff --git a/spec/unit/provider/remote_file/content_spec.rb b/spec/unit/provider/remote_file/content_spec.rb index 1afc95fa48..e105f84bd3 100644 --- a/spec/unit/provider/remote_file/content_spec.rb +++ b/spec/unit/provider/remote_file/content_spec.rb @@ -161,7 +161,7 @@ describe Chef::Provider::RemoteFile::Content do # https://github.com/chef/chef/pull/1358#issuecomment-40853299 def create_exception(exception_class) - if [ Net::HTTPServerException, Net::HTTPFatalError ].include? exception_class + if [ Net::HTTPClientException, Net::HTTPFatalError ].include? exception_class exception_class.new("message", { "something" => 1 }) else exception_class.new @@ -177,7 +177,7 @@ describe Chef::Provider::RemoteFile::Content do Errno::ENOENT, Errno::EACCES, Timeout::Error, - Net::HTTPServerException, + Net::HTTPClientException, Net::HTTPFatalError, Net::FTPError, Errno::ETIMEDOUT, diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index c532ba0ae9..cec931dd70 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -494,7 +494,7 @@ describe Chef::ResourceReporter do @node = Chef::Node.new @node.name("spitfire") @exception = ArgumentError.new - allow(@exception).to receive(:inspect).and_return("Net::HTTPServerException") + allow(@exception).to receive(:inspect).and_return("Net::HTTPClientException") allow(@exception).to receive(:message).and_return("Object not found") allow(@exception).to receive(:backtrace).and_return(@backtrace) @resource_reporter.run_list_expand_failed(@node, @exception) @@ -505,7 +505,7 @@ describe Chef::ResourceReporter do it "includes the exception type in the event data" do expect(@report).to have_key("data") expect(@report["data"]["exception"]).to have_key("class") - expect(@report["data"]["exception"]["class"]).to eq("Net::HTTPServerException") + expect(@report["data"]["exception"]["class"]).to eq("Net::HTTPClientException") end it "includes the exception message in the event data" do @@ -615,7 +615,7 @@ describe Chef::ResourceReporter do before do # 404 getting the run_id @response = Net::HTTPNotFound.new("a response body", "404", "Not Found") - @error = Net::HTTPServerException.new("404 message", @response) + @error = Net::HTTPClientException.new("404 message", @response) expect(@rest_client).to receive(:post) .with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, @@ -645,7 +645,7 @@ describe Chef::ResourceReporter do before do # 500 getting the run_id @response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error") - @error = Net::HTTPServerException.new("500 message", @response) + @error = Net::HTTPClientException.new("500 message", @response) expect(@rest_client).to receive(:post) .with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }) @@ -675,7 +675,7 @@ describe Chef::ResourceReporter do Chef::Config[:enable_reporting_url_fatals] = true # 500 getting the run_id @response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error") - @error = Net::HTTPServerException.new("500 message", @response) + @error = Net::HTTPClientException.new("500 message", @response) expect(@rest_client).to receive(:post) .with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }) @@ -690,7 +690,7 @@ describe Chef::ResourceReporter do expect(Chef::Log).to receive(:error).with(/500/) expect do @resource_reporter.run_started(@run_status) - end.to raise_error(Net::HTTPServerException) + end.to raise_error(Net::HTTPClientException) end end @@ -746,7 +746,7 @@ describe Chef::ResourceReporter do it "should log 4xx errors" do response = Net::HTTPClientError.new("forbidden", "403", "Forbidden") - error = Net::HTTPServerException.new("403 message", response) + error = Net::HTTPClientException.new("403 message", response) allow(@rest_client).to receive(:raw_request).and_raise(error) expect(Chef::Log).to receive(:error).with(/403/) diff --git a/spec/unit/user_v1_spec.rb b/spec/unit/user_v1_spec.rb index 074a68840e..37b2252492 100644 --- a/spec/unit/user_v1_spec.rb +++ b/spec/unit/user_v1_spec.rb @@ -312,7 +312,7 @@ describe Chef::UserV1 do describe "Versioned API Interactions" do let(:response_406) { OpenStruct.new(code: "406") } - let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) } + let(:exception_406) { Net::HTTPClientException.new("406 Not Acceptable", response_406) } before (:each) do @user = Chef::UserV1.new @@ -374,7 +374,7 @@ describe Chef::UserV1 do context "when the server returns a 400" do let(:response_400) { OpenStruct.new(code: "400") } - let(:exception_400) { Net::HTTPServerException.new("400 Bad Request", response_400) } + let(:exception_400) { Net::HTTPClientException.new("400 Bad Request", response_400) } context "when the 400 was due to public / private key fields no longer being supported" do let(:response_body_400) { '{"error":["Since Server API v1, all keys must be updated via the keys endpoint. "]}' } -- cgit v1.2.1