diff options
author | Claire McQuin <claire@getchef.com> | 2015-05-08 17:30:33 -0700 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2015-05-27 14:16:23 -0400 |
commit | 9890e02b3bc16ddc2416497ad39acc40afe98c32 (patch) | |
tree | 36155fd108e16b599b1f5a7fcc8786e3452cd710 /lib | |
parent | 67b9fdc307fd0a7480cc4f11c18540763ec43b09 (diff) | |
download | chef-9890e02b3bc16ddc2416497ad39acc40afe98c32.tar.gz |
Save and report audit phase failure on run_completed or run_failed.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/audit/audit_reporter.rb | 11 | ||||
-rw-r--r-- | lib/chef/formatters/doc.rb | 6 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb index a4f84ed7eb..8268de3aa7 100644 --- a/lib/chef/audit/audit_reporter.rb +++ b/lib/chef/audit/audit_reporter.rb @@ -34,6 +34,7 @@ class Chef @rest_client = rest_client # Ruby 1.9.3 and above "enumerate their values in the order that the corresponding keys were inserted." @ordered_control_groups = Hash.new + @exception = nil end def run_context @@ -59,6 +60,7 @@ class Chef # known control groups. def audit_phase_failed(error) # The stacktrace information has already been logged elsewhere + @exception = error Chef::Log.debug("Audit Reporter failed.") ordered_control_groups.each do |name, control_group| audit_data.add_control_group(control_group) @@ -116,8 +118,10 @@ class Chef Chef::Log.debug("Sending audit report (run-id: #{audit_data.run_id})") run_data = audit_data.to_hash - if error - run_data[:error] = "#{error.class.to_s}: #{error.message}\n#{error.backtrace.join("\n")}" + if @exception || error + errors = [@exception, error].uniq.compact + errors_messages = errors.map { |err| "#{err.class.to_s}: #{err.message}\n#{err.backtrace.join("\n")}" } + run_data[:error] = errors_messages.join("\n") end Chef::Log.debug "Audit Report:\n#{Chef::JSONCompat.to_json_pretty(run_data)}" @@ -164,6 +168,9 @@ class Chef time.utc.iso8601.to_s end + def error_message_for_run_data(error) + "#{err.class.to_s}: #{err.message}\n#{err.backtrace.join("\n")}" + end end end end diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb index 945bc71f2f..e63c764cbf 100644 --- a/lib/chef/formatters/doc.rb +++ b/lib/chef/formatters/doc.rb @@ -188,8 +188,10 @@ class Chef puts_line "Audit phase exception:" indent puts_line "#{error.message}" - error.backtrace.each do |l| - puts_line l + if error.backtrace + error.backtrace.each do |l| + puts_line l + end end end |