Skip to content

Commit 71a3e37

Browse files
committed
[CHEF-2224] default exception handler prints the node data
1 parent 6712106 commit 71a3e37

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎chef/lib/chef/application/client.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
require 'chef/daemon'
2323
require 'chef/log'
2424
require 'chef/rest'
25+
require 'chef/handler/error_report'
2526

2627

2728
class Chef::Application::Client < Chef::Application
@@ -150,6 +151,9 @@ def reconfigure
150151
super
151152

152153
Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url
154+
unless Chef::Config[:exception_handlers].any? {|h| Chef::Handler::ErrorReport === h}
155+
Chef::Config[:exception_handlers] << Chef::Handler::ErrorReport.new
156+
end
153157

154158
if Chef::Config[:daemonize]
155159
Chef::Config[:interval] ||= 1800
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Author:: Adam Jacob (<adam@opscode.com>)
3+
# Copyright:: Copyright (c) 2010 Opscode, Inc.
4+
# License:: Apache License, Version 2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
require 'chef/handler'
20+
require 'chef/resource/directory'
21+
22+
class Chef
23+
class Handler
24+
class ErrorReport < ::Chef::Handler
25+
26+
def report
27+
Chef::Log.fatal("Saving node information to #{report_path}")
28+
29+
File.open(report_path, "w") do |file|
30+
file.puts Chef::JSONCompat.to_json_pretty(data)
31+
end
32+
end
33+
34+
def report_path
35+
File.join(Dir.tmpdir, "failed-run-data.json")
36+
end
37+
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)