summaryrefslogtreecommitdiff
path: root/lib/chef/formatters
diff options
context:
space:
mode:
authortylercloke <tylercloke@gmail.com>2015-05-01 15:35:29 -0700
committertylercloke <tylercloke@gmail.com>2015-05-04 13:18:30 -0700
commita93fc69d0c09a9e8fc5f5cdac865d91db4ea012f (patch)
treef47e12f4222c380f681bffc8ef569e6e8278cf18 /lib/chef/formatters
parent2160fb4f917fb9f843c2bbd11093cbb1c2873482 (diff)
downloadchef-a93fc69d0c09a9e8fc5f5cdac865d91db4ea012f.tar.gz
Nice error handling for unsupported API version in formatters/*.rb.
Diffstat (limited to 'lib/chef/formatters')
-rw-r--r--lib/chef/formatters/error_inspectors/api_error_formatting.rb17
-rw-r--r--lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb2
-rw-r--r--lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb2
-rw-r--r--lib/chef/formatters/error_inspectors/node_load_error_inspector.rb2
-rw-r--r--lib/chef/formatters/error_inspectors/registration_error_inspector.rb4
-rw-r--r--lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb2
6 files changed, 29 insertions, 0 deletions
diff --git a/lib/chef/formatters/error_inspectors/api_error_formatting.rb b/lib/chef/formatters/error_inspectors/api_error_formatting.rb
index 652d478b40..ec25f4e903 100644
--- a/lib/chef/formatters/error_inspectors/api_error_formatting.rb
+++ b/lib/chef/formatters/error_inspectors/api_error_formatting.rb
@@ -16,6 +16,8 @@
# limitations under the License.
#
+require 'chef/http/authenticator'
+
class Chef
module Formatters
@@ -65,6 +67,21 @@ E
error_description.section("Server Response:",format_rest_error)
end
+ def describe_406_error(error_description, response)
+ if Chef::JSONCompat.from_json(response.body)["error"] == "invalid-x-ops-server-api-version"
+ min_version = Chef::JSONCompat.from_json(response.body)["min_version"]
+ max_version = Chef::JSONCompat.from_json(response.body)["max_version"]
+ error_description.section("Incompatible server API version:",<<-E)
+This version of Chef is not supported by the Chef server you sent this request to
+This version of Chef requires a server API version of #{Chef::HTTP::Authenticator::SERVER_API_VERSION}
+The Chef server you sent the request to supports a min API version of #{min_version} and a max API version of #{max_version}
+Please either update your Chef client or server to be a compatible set
+E
+ else
+ describe_http_error(error_description)
+ end
+ end
+
def describe_500_error(error_description)
error_description.section("Unknown Server Error:",<<-E)
The server had a fatal error attempting to load the node data.
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 aa5eb8485d..e011fa9d9b 100644
--- a/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb
+++ b/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb
@@ -72,6 +72,8 @@ E
describe_500_error(error_description)
when Net::HTTPBadGateway, Net::HTTPServiceUnavailable
describe_503_error(error_description)
+ when Net::HTTPNotAcceptable
+ describe_406_error(error_description, response)
else
describe_http_error(error_description)
end
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 0cb849a17f..971dbd664e 100644
--- a/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb
+++ b/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb
@@ -67,6 +67,8 @@ class Chef
describe_500_error(error_description)
when Net::HTTPBadGateway, Net::HTTPServiceUnavailable, Net::HTTPGatewayTimeOut
describe_503_error(error_description)
+ when Net::HTTPNotAcceptable
+ describe_406_error(error_description, response)
else
describe_http_error(error_description)
end
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 e257ee30c0..d81a9f7cc8 100644
--- a/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb
+++ b/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb
@@ -84,6 +84,8 @@ E
describe_500_error(error_description)
when Net::HTTPBadGateway, Net::HTTPServiceUnavailable
describe_503_error(error_description)
+ when Net::HTTPNotAcceptable
+ describe_406_error(error_description, response)
else
describe_http_error(error_description)
end
diff --git a/lib/chef/formatters/error_inspectors/registration_error_inspector.rb b/lib/chef/formatters/error_inspectors/registration_error_inspector.rb
index f31b348278..dbd23f4a52 100644
--- a/lib/chef/formatters/error_inspectors/registration_error_inspector.rb
+++ b/lib/chef/formatters/error_inspectors/registration_error_inspector.rb
@@ -9,6 +9,8 @@ class Chef
# TODO: Lots of duplication with the node_load_error_inspector, just
# slightly tweaked to talk about validation keys instead of other keys.
class RegistrationErrorInspector
+ include APIErrorFormatting
+
attr_reader :exception
attr_reader :node_name
attr_reader :config
@@ -94,6 +96,8 @@ E
error_description.section("Relevant Config Settings:",<<-E)
chef_server_url "#{server_url}"
E
+ when Net::HTTPNotAcceptable
+ describe_406_error(error_description, response)
when Net::HTTPInternalServerError
error_description.section("Unknown Server Error:",<<-E)
The server had a fatal error attempting to load the node data.
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 ac19a983af..818228276e 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
@@ -98,6 +98,8 @@ E
error_description.section("Possible Causes:",<<-E)
* Your client (#{username}) may have misconfigured authorization permissions.
E
+ when Net::HTTPNotAcceptable
+ describe_406_error(error_description, response)
when Net::HTTPInternalServerError
error_description.section("Unknown Server Error:",<<-E)
The server had a fatal error attempting to load a role.