在 Chef 中,为什么这段代码没有捕捉到 bash 资源中抛出的异常?如果我运行这段代码,即使抛出异常,我也永远无法访问 python 资源。该错误是预期的,这就是为什么我要抓住它,然后转到 pymongo 并以这种方式修复它。
begin
bash "mongo fix" do
code "mongo --verbose #{filename}"
action :run
end
rescue
python 'pymongo reconfig' do
code "Pymongo does a catch and reconfig"
end
end
这是异常输出
[2013-03-05T20:03:55+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: bash[mongo fix (noudata::mongo line 77) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '253'
---- Begin output of "bash" "/tmp/chef-script20130305-3916-14xxhn5-0" ----
STDOUT: MongoDB shell version: 2.2.3
Tue Mar 5 20:03:55 versionCmpTest passed
Tue Mar 5 20:03:55 versionArrayTest passed
connecting to: test
Tue Mar 5 20:03:55 creating new connection to:127.0.0.1:27017
Tue Mar 5 20:03:55 BackgroundJob starting: ConnectBG
Tue Mar 5 20:03:55 connected connection!
true
{
"errmsg" : "replSetReconfig command must be sent to the current replica set primary.",
"ok" : 0
}
Tue Mar 5 20:03:55 uncaught exception: [object bson_object]
failed to load: /tmp/test.js
STDERR:
---- End output of "bash" "/tmp/chef-script20130305-3916-14xxhn5-0" ----
Ran "bash" "/tmp/chef-script20130305-3916-14xxhn5-0" returned 253