Skip to content

Commit

Permalink
Merge pull request #456 from cprice-puppet/refactor/master/12359-impr…
Browse files Browse the repository at this point in the history
…ove-backtrace-logging

Refactor/master/12359 improve backtrace logging
  • Loading branch information
slippycheeze committed Feb 8, 2012
2 parents 142b249 + e3c46b4 commit 9859517
Show file tree
Hide file tree
Showing 57 changed files with 163 additions and 197 deletions.
6 changes: 2 additions & 4 deletions lib/puppet/agent.rb
Expand Up @@ -49,8 +49,7 @@ def run(*args)
rescue SystemExit,NoMemoryError
raise
rescue Exception => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not run #{client_class}: #{detail}"
Puppet.log_exception(detail, "Could not run #{client_class}: #{detail}")
end
end
end
Expand Down Expand Up @@ -129,8 +128,7 @@ def with_client
rescue SystemExit,NoMemoryError
raise
rescue Exception => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not create instance of #{client_class}: #{detail}"
Puppet.log_exception(detail, "Could not create instance of #{client_class}: #{detail}")
return
end
yield @client
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/application.rb
Expand Up @@ -403,8 +403,7 @@ def help
def exit_on_fail(message, code = 1)
yield
rescue ArgumentError, RuntimeError, NotImplementedError => detail
puts detail.backtrace if Puppet[:trace]
$stderr.puts "Could not #{message}: #{detail}"
Puppet.log_exception(detail, "Could not #{message}: #{detail}")
exit(code)
end

Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/application/agent.rb
Expand Up @@ -68,8 +68,7 @@ def preinit
Puppet::Util::Log.newdestination(arg)
options[:setdest] = true
rescue => detail
puts detail.backtrace if Puppet[:debug]
$stderr.puts detail.to_s
Puppet.log_exception(detail)
end
end

Expand Down Expand Up @@ -328,8 +327,7 @@ def onetime
@agent.should_fork = false
exitstatus = @agent.run
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err detail.to_s
Puppet.log_exception(detail)
end

@daemon.stop(:exit => false)
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/application/apply.rb
Expand Up @@ -223,8 +223,7 @@ def main
exit(0)
end
rescue => detail
puts detail.backtrace if Puppet[:trace]
$stderr.puts detail.message
Puppet.log_exception(detail)
exit(1)
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/application/cert.rb
Expand Up @@ -189,8 +189,7 @@ def main
@ca.apply(:revoke, options.merge(:to => hosts)) if subcommand == :destroy
@ca.apply(subcommand, options.merge(:to => hosts, :digest => @digest))
rescue => detail
puts detail.backtrace if Puppet[:trace]
puts detail.to_s
Puppet.log_exception(detail)
exit(24)
end
end
Expand Down Expand Up @@ -219,8 +218,7 @@ def setup
begin
@ca = Puppet::SSL::CertificateAuthority.new
rescue => detail
puts detail.backtrace if Puppet[:trace]
puts detail.to_s
Puppet.log_exception(detail)
exit(23)
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/application/device.rb
Expand Up @@ -43,8 +43,7 @@ def preinit
Puppet::Util::Log.newdestination(arg)
options[:setdest] = true
rescue => detail
puts detail.backtrace if Puppet[:debug]
$stderr.puts detail.to_s
Puppet.log_exception(detail)
end
end

Expand Down Expand Up @@ -190,8 +189,7 @@ def main
configurer = Puppet::Configurer.new
report = configurer.run(:network_device => true)
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err detail.to_s
Puppet.log_exception(detail)
ensure
Puppet.settings.set_value(:vardir, vardir, :cli)
Puppet.settings.set_value(:confdir, confdir, :cli)
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/application/doc.rb
Expand Up @@ -182,8 +182,7 @@ def rdoc
Puppet::Util::RDoc.rdoc(options[:outputdir], files, options[:charset])
end
rescue => detail
puts detail.backtrace if Puppet[:trace]
$stderr.puts "Could not generate documentation: #{detail}"
Puppet.log_exception(detail, "Could not generate documentation: #{detail}")
exit_code = 1
end
exit exit_code
Expand All @@ -201,8 +200,7 @@ def other
# Add the per-section text, but with no ToC
text += section.send(options[:format], with_contents)
rescue => detail
puts detail.backtrace
$stderr.puts "Could not generate reference #{name}: #{detail}"
Puppet.log_exception(detail, "Could not generate reference #{name}: #{detail}")
exit_code = 1
next
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/application/face_base.rb
Expand Up @@ -244,8 +244,7 @@ def main
status = true

rescue Exception => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err detail.to_s
Puppet.log_exception(detail)
Puppet.err "Try 'puppet help #{@face.name} #{@action.name}' for usage"

ensure
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/application/filebucket.rb
Expand Up @@ -181,8 +181,7 @@ def setup
@client = Puppet::FileBucket::Dipper.new(:Server => Puppet[:server])
end
rescue => detail
$stderr.puts detail
puts detail.backtrace if Puppet[:trace]
Puppet.log_exception(detail)
exit(1)
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/application/inspect.rb
Expand Up @@ -136,8 +136,7 @@ def run_command
begin
audited_resource = ral_resource.to_resource
rescue StandardError => detail
puts detail.backtrace if Puppet[:trace]
ral_resource.err "Could not inspect #{ral_resource}; skipping: #{detail}"
ral_resource.log_exception(detail, "Could not inspect #{ral_resource}; skipping: #{detail}")
audited_attributes.each do |name|
event = ral_resource.event(
:property => name,
Expand Down Expand Up @@ -183,8 +182,7 @@ def run_command
begin
Puppet::Transaction::Report.indirection.save(@report)
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not send report: #{detail}"
Puppet.log_exception(detail, "Could not send report: #{detail}")
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/application/kick.rb
Expand Up @@ -248,8 +248,7 @@ def run_for_host(host)
result = run.status
puts "status is #{result}"
rescue => detail
puts detail.backtrace if Puppet[:trace]
$stderr.puts "Host #{host} failed: #{detail}\n"
Puppet.log_exception(detail, "Host #{host} failed: #{detail}\n")
exit(2)
end

Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/application/master.rb
Expand Up @@ -20,8 +20,7 @@ class Puppet::Application::Master < Puppet::Application
Puppet::Util::Log.newdestination(arg)
options[:setdest] = true
rescue => detail
puts detail.backtrace if Puppet[:debug]
$stderr.puts detail.to_s
Puppet.log_exception(detail)
end
end

Expand Down Expand Up @@ -177,8 +176,7 @@ def main
begin
Puppet::Util.chuser
rescue => detail
puts detail.backtrace if Puppet[:trace]
$stderr.puts "Could not change user to #{Puppet[:user]}: #{detail}"
Puppet.log_exception(detail, "Could not change user to #{Puppet[:user]}: #{detail}")
exit(39)
end
end
Expand Down
9 changes: 3 additions & 6 deletions lib/puppet/application/queue.rb
Expand Up @@ -113,8 +113,7 @@ def help
Puppet::Util::Log.newdestination(arg)
options[:setdest] = true
rescue => detail
puts detail.backtrace if Puppet[:debug]
$stderr.puts detail.to_s
Puppet.log_exception(detail)
end
end

Expand All @@ -123,8 +122,7 @@ def help
Puppet::Util::Log.newdestination(arg)
options[:setdest] = true
rescue => detail
puts detail.backtrace if Puppet[:debug]
$stderr.puts detail.to_s
Puppet.log_exception(detail)
end
end

Expand All @@ -139,8 +137,7 @@ def main
begin
Puppet::Resource::Catalog.indirection.save(catalog)
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not save queued catalog for #{catalog.name}: #{detail}"
Puppet.log_exception(detail, "Could not save queued catalog for #{catalog.name}: #{detail}")
end
end
end
Expand Down
33 changes: 13 additions & 20 deletions lib/puppet/configurer.rb
Expand Up @@ -51,14 +51,13 @@ def dostorage
Puppet::Util::Storage.load
@compile_time ||= Puppet::Util::Storage.cache(:configuration)[:compile_time]
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Corrupt state file #{Puppet[:statefile]}: #{detail}"
begin
::File.unlink(Puppet[:statefile])
retry
rescue => detail
raise Puppet::Error.new("Cannot remove #{Puppet[:statefile]}: #{detail}")
end
Puppet.log_exception(detail, "Removing corrupt state file #{Puppet[:statefile]}: #{detail}")
begin
::File.unlink(Puppet[:statefile])
retry
rescue => detail
raise Puppet::Error.new("Cannot remove #{Puppet[:statefile]}: #{detail}")
end
end

# Just so we can specify that we are "the" instance.
Expand Down Expand Up @@ -154,8 +153,7 @@ def run(options = {})
rescue SystemExit,NoMemoryError
raise
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Failed to apply catalog: #{detail}"
Puppet.log_exception(detail, "Failed to apply catalog: #{detail}")
return nil
ensure
execute_postrun_command or return nil
Expand All @@ -175,8 +173,7 @@ def send_report(report)
save_last_run_summary(report)
Puppet::Transaction::Report.indirection.save(report) if Puppet[:report]
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not send report: #{detail}"
Puppet.log_exception(detail, "Could not send report: #{detail}")
end

def save_last_run_summary(report)
Expand All @@ -192,8 +189,7 @@ def save_last_run_summary(report)
ral.host_config = false
ral.apply
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not save last run local report: #{detail}"
Puppet.log_exception(detail, "Could not save last run local report: #{detail}")
end

private
Expand Down Expand Up @@ -222,8 +218,7 @@ def execute_from_setting(setting)
Puppet::Util::Execution.execute([command])
true
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not run command from #{setting}: #{detail}"
Puppet.log_exception(detail, "Could not run command from #{setting}: #{detail}")
false
end
end
Expand All @@ -236,8 +231,7 @@ def retrieve_catalog_from_cache(fact_options)
Puppet.notice "Using cached catalog"
result
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not retrieve catalog from cache: #{detail}"
Puppet.log_exception(detail, "Could not retrieve catalog from cache: #{detail}")
return nil
end

Expand All @@ -250,8 +244,7 @@ def retrieve_new_catalog(fact_options)
rescue SystemExit,NoMemoryError
raise
rescue Exception => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not retrieve catalog from remote server: #{detail}"
Puppet.log_exception(detail, "Could not retrieve catalog from remote server: #{detail}")
return nil
end
end
3 changes: 1 addition & 2 deletions lib/puppet/configurer/downloader.rb
Expand Up @@ -37,8 +37,7 @@ def evaluate
end
end
rescue Puppet::Error, Timeout::Error => detail
puts detail.backtrace if Puppet[:debug]
Puppet.err "Could not retrieve #{name}: #{detail}"
Puppet.log_exception(detail, "Could not retrieve #{name}: #{detail}")
end

files
Expand Down
5 changes: 3 additions & 2 deletions lib/puppet/configurer/fact_handler.rb
Expand Up @@ -20,8 +20,9 @@ def find_facts
rescue SystemExit,NoMemoryError
raise
rescue Exception => detail
puts detail.backtrace if Puppet[:trace]
raise Puppet::Error, "Could not retrieve local facts: #{detail}"
message = "Could not retrieve local facts: #{detail}"
Puppet.log_exception(detail, message)
raise Puppet::Error, message
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/face/catalog.rb
Expand Up @@ -75,8 +75,7 @@
catalog.apply(:report => report)
end
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Failed to apply catalog: #{detail}"
Puppet.log_exception(detail, "Failed to apply catalog: #{detail}")
end

report.finalize_report
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/face/report.rb
Expand Up @@ -21,8 +21,7 @@
Puppet::Face[:report, "0.0.1"].save(report)
Puppet.notice "Uploaded report for #{report.name}"
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not send report: #{detail}"
Puppet.log_exception(detail, "Could not send report: #{detail}")
end
EOT

Expand All @@ -48,8 +47,7 @@
Puppet::Face[:report, "0.0.1"].save(report)
Puppet.notice "Uploaded report for #{report.name}"
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not send report: #{detail}"
Puppet.log_exception(detail, "Could not send report: #{detail}")
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/puppet/file_bucket/dipper.rb
Expand Up @@ -46,8 +46,9 @@ def backup(file)

return file_bucket_file.checksum_data
rescue => detail
puts detail.backtrace if Puppet[:trace]
raise Puppet::Error, "Could not back up #{file}: #{detail}"
message = "Could not back up #{file}: #{detail}"
Puppet.log_exception(detail, message)
raise Puppet::Error, message
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/file_serving/configuration.rb
Expand Up @@ -110,8 +110,7 @@ def readconfig(check = true)
newmounts = @parser.parse
@mounts = newmounts
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Error parsing fileserver configuration: #{detail}; using old configuration"
Puppet.log_exception(detail, "Error parsing fileserver configuration: #{detail}; using old configuration")
end

ensure
Expand Down
5 changes: 3 additions & 2 deletions lib/puppet/indirector/catalog/compiler.rb
Expand Up @@ -89,8 +89,9 @@ def find_node(name)
begin
return nil unless node = Puppet::Node.indirection.find(name)
rescue => detail
puts detail.backtrace if Puppet[:trace]
raise Puppet::Error, "Failed when searching for node #{name}: #{detail}"
message = "Failed when searching for node #{name}: #{detail}"
Puppet.log_exception(detail, message)
raise Puppet::Error, message
end


Expand Down
5 changes: 3 additions & 2 deletions lib/puppet/indirector/face.rb
Expand Up @@ -41,8 +41,9 @@ def call_indirection_method(method, key, options)
begin
result = indirection.__send__(method, key, options)
rescue => detail
puts detail.backtrace if Puppet[:trace]
raise "Could not call '#{method}' on '#{indirection_name}': #{detail}"
message = "Could not call '#{method}' on '#{indirection_name}': #{detail}"
Puppet.log_exception(detail, message)
raise message
end

return result
Expand Down

0 comments on commit 9859517

Please sign in to comment.