diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-04-06 10:16:45 -0700 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2015-04-20 15:30:21 -0400 |
commit | 5cd4ee159983f4cfa88b772072d86745f1993999 (patch) | |
tree | 13cf4f0f2011541c9613e05d1366a392c591a2dd /lib | |
parent | 8a9cf7f0095254a4c01c86de43c3e60f5c9a0045 (diff) | |
download | chef-5cd4ee159983f4cfa88b772072d86745f1993999.tar.gz |
Fix nil pointer for windows event logger
It is possible for the run to fail and no run_status to even have
been set. This resolves issue #2996
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/event_loggers/windows_eventlog.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/chef/event_loggers/windows_eventlog.rb b/lib/chef/event_loggers/windows_eventlog.rb index 6f5ef627fb..37dcdc8693 100644 --- a/lib/chef/event_loggers/windows_eventlog.rb +++ b/lib/chef/event_loggers/windows_eventlog.rb @@ -88,15 +88,21 @@ class Chef #Exception message: %4 #Exception backtrace: %5 def run_failed(e) + data = + if @run_status + [@run_status.run_id, + @run_status.elapsed_time.to_s] + else + ["UNKNOWN", "UNKNOWN"] + end + @eventlog.report_event( :event_type => ::Win32::EventLog::ERROR_TYPE, :source => SOURCE, :event_id => RUN_FAILED_EVENT_ID, - :data => [@run_status.run_id, - @run_status.elapsed_time.to_s, - e.class.name, - e.message, - e.backtrace.join("\n")] + :data => data + [e.class.name, + e.message, + e.backtrace.join("\n")] ) end |