summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2012-10-19 11:09:43 -0700
committerBryan McLellan <btm@opscode.com>2012-10-19 11:09:43 -0700
commitaff442aae93b4618322ef0861ee9063c422c4d0f (patch)
tree9d67c6af589fee3a0fb9285c7bafc23af5dea00b
parent70e0f24b1c223878d4783bfa47a47a2e009dea42 (diff)
downloadchef-aff442aae93b4618322ef0861ee9063c422c4d0f.tar.gz
Expose http error code on reporting exception
When the server returns an exception we need to at least know what the error code was to assist in debugging.
-rw-r--r--chef/lib/chef/resource_reporter.rb6
-rw-r--r--chef/spec/unit/resource_reporter_spec.rb11
2 files changed, 11 insertions, 6 deletions
diff --git a/chef/lib/chef/resource_reporter.rb b/chef/lib/chef/resource_reporter.rb
index 8155f8b7a7..fe28f26d73 100644
--- a/chef/lib/chef/resource_reporter.rb
+++ b/chef/lib/chef/resource_reporter.rb
@@ -118,13 +118,13 @@ class Chef
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
if !e.response || e.response.code.to_s != "404"
if Chef::Config[:enable_reporting_url_fatals]
- Chef::Log.error("Received exception attempting to generate run history id (URL Path: #{resource_history_url}), and enable_reporting_url_fatals is set, aborting run.")
+ Chef::Log.error("Received exception #{"(" + e.response.code + ") " if e.response.code}attempting to generate run history id (URL Path: #{resource_history_url}), and enable_reporting_url_fatals is set, aborting run.")
raise
else
- Chef::Log.info("Received exception attempting to generate run history id (URL Path: #{resource_history_url}), disabling reporting for this run.")
+ Chef::Log.info("Received exception #{"(" + e.response.code + ") " if e.response.code}attempting to generate run history id (URL Path: #{resource_history_url}), disabling reporting for this run.")
end
else
- Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
+ Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported on server.")
end
@reporting_enabled = false
end
diff --git a/chef/spec/unit/resource_reporter_spec.rb b/chef/spec/unit/resource_reporter_spec.rb
index e0bc3a0f2f..51f4ba7c19 100644
--- a/chef/spec/unit/resource_reporter_spec.rb
+++ b/chef/spec/unit/resource_reporter_spec.rb
@@ -441,18 +441,23 @@ describe Chef::ResourceReporter do
@rest_client.should_receive(:post_rest).
with("reports/nodes/spitfire/runs", {:action => :begin}).
and_raise(@error)
- @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
end
it "assumes the feature is not enabled" do
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
@resource_reporter.reporting_enabled?.should be_false
end
it "does not send a resource report to the server" do
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
@rest_client.should_not_receive(:post_rest)
@resource_reporter.run_completed(@node)
end
+ it "prints an error about the error" do
+ Chef::Log.should_receive(:info).with(/500/)
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
+ end
end
context "when the server returns a 500 to the client and enable_reporting_url_fatals is true" do
@@ -471,12 +476,12 @@ describe Chef::ResourceReporter do
Chef::Config[:enable_reporting_url_fatals] = @enable_reporting_url_fatals
end
- it "fails the run" do
+ it "fails the run and prints an message about the error" do
+ Chef::Log.should_receive(:error).with(/500/)
lambda {
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
}.should raise_error(Net::HTTPServerException)
end
-
end
context "after creating the run history document" do