summaryrefslogtreecommitdiff
path: root/chef/lib/chef
diff options
context:
space:
mode:
authorAdam Jacob <adam@opscode.com>2011-04-01 12:09:04 -0700
committerDaniel DeLeo <dan@opscode.com>2011-04-01 17:32:19 -0700
commit22690688d761ebe37afed025eaa77b48d4c820a6 (patch)
treec973fcf72287e8ed62bb4a6effbc9efb2c7d5062 /chef/lib/chef
parent974e0ce27527a92ebfa988057855899e7b115330 (diff)
downloadchef-22690688d761ebe37afed025eaa77b48d4c820a6.tar.gz
Adding a stack trace file
Diffstat (limited to 'chef/lib/chef')
-rw-r--r--chef/lib/chef/application.rb13
-rw-r--r--chef/lib/chef/application/client.rb9
-rw-r--r--chef/lib/chef/application/solo.rb8
3 files changed, 20 insertions, 10 deletions
diff --git a/chef/lib/chef/application.rb b/chef/lib/chef/application.rb
index f68a1295e5..1ad756a5d0 100644
--- a/chef/lib/chef/application.rb
+++ b/chef/lib/chef/application.rb
@@ -19,6 +19,7 @@ require 'chef/config'
require 'chef/exceptions'
require 'chef/log'
require 'mixlib/cli'
+require 'tmpdir'
class Chef::Application
include Mixlib::CLI
@@ -121,6 +122,18 @@ class Chef::Application
class << self
+ def debug_stacktrace(e)
+ message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
+ filename = File.join(Dir.tmpdir, "chef-stacktrace.out")
+ Chef::Log.fatal("Stacktrace dumped to #{filename}")
+ Chef::Log.debug(message)
+ chef_stacktrace_out = File.open(filename, "w")
+ chef_stacktrace_out.puts "Generated at #{Time.now.to_s}"
+ chef_stacktrace_out.puts message
+ chef_stacktrace_out.close
+ true
+ end
+
# Log a fatal error message to both STDERR and the Logger, exit the application
def fatal!(msg, err = -1)
STDERR.puts("FATAL: #{msg}")
diff --git a/chef/lib/chef/application/client.rb b/chef/lib/chef/application/client.rb
index 2bae92daf8..e736cfb0e6 100644
--- a/chef/lib/chef/application/client.rb
+++ b/chef/lib/chef/application/client.rb
@@ -224,18 +224,17 @@ class Chef::Application::Client < Chef::Application
Chef::Application.exit! "Exiting", 0
end
rescue SystemExit => e
- Chef::Log.debug("#{e.class}: #{e}\n#{e.backtrace.join("\n")}")
- Chef::Application.fatal!("Aborting chef (#{e.class}: #{e.message})", 5)
+ raise
rescue Exception => e
if Chef::Config[:interval]
Chef::Log.error("#{e.class}: #{e}")
- Chef::Log.debug("#{e.class}: #{e}\n#{e.backtrace.join("\n")}")
+ Chef::Application.debug_stacktrace(e)
Chef::Log.error("Sleeping for #{Chef::Config[:interval]} seconds before trying again")
sleep Chef::Config[:interval]
retry
else
- Chef::Log.debug("#{e.class}: #{e}\n#{e.backtrace.join("\n")}")
- Chef::Application.fatal!("#{e.class}: #{e.message}", 4)
+ Chef::Application.debug_stacktrace(e)
+ Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
end
ensure
GC.start
diff --git a/chef/lib/chef/application/solo.rb b/chef/lib/chef/application/solo.rb
index 5dfba6f7b6..b6d4990d84 100644
--- a/chef/lib/chef/application/solo.rb
+++ b/chef/lib/chef/application/solo.rb
@@ -198,8 +198,7 @@ class Chef::Application::Solo < Chef::Application
Chef::Application.exit! "Exiting", 0
end
rescue SystemExit => e
- Chef::Log.debug("#{e.class}: #{e}\n#{e.backtrace.join("\n")}")
- Chef::Application.fatal!("Aborting chef (#{e.class}: #{e.message})", 5)
+ raise
rescue Exception => e
if Chef::Config[:interval]
Chef::Log.error("#{e.class}: #{e}")
@@ -208,9 +207,8 @@ class Chef::Application::Solo < Chef::Application
sleep Chef::Config[:interval]
retry
else
- Chef::Log.debug("#{e.class}: #{e}\n#{e.backtrace.join("\n")}")
- Chef::Application.fatal!("#{e.class}: #{e.message}", 4)
- raise
+ Chef::Application.debug_stacktrace(e)
+ Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
end
ensure
GC.start