summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@chef.io>2015-11-05 16:28:39 -0500
committerBryan McLellan <btm@chef.io>2015-11-06 10:26:48 -0500
commitbd18b913954333f67dc4da4dc3f330298247b3f1 (patch)
tree0fa4d92638a6f85cdd3256b575ce70f40852d902
parent2e09c06915ca8602223d83bf351d439d5c7e9e4f (diff)
downloadchef-btm/knife-backtrace.tar.gz
Avoid squashing/humanizing the exception when config[:verbosity] == 2btm/knife-backtrace
We create an instance of Chef::Knife::Bootstrap in knife-ec2, but we've already processed ARGV so we substitute and process an empty argv. config[:verbosity] comes from Chef::Application::Knife. Normally we merge those options with the ones from the knife subcommand in Chef::Knife.run. Since we don't in this case, we don't set it to the default of 0 that is specified there, leaving it nil. We set Chef::Config[:verbosity] to config[:verbosity] in Chef::Knife#initialize which now becomes nil. This change makes it so we do not update Chef::Config[:verbosity] if config[:verbosity] is nil, so that later when we rescue we don't call humanize_exception if Chef::Config[:verbosity] is 2.
-rw-r--r--lib/chef/knife.rb2
-rw-r--r--spec/unit/knife_spec.rb15
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb
index fed2ad4cfa..6fa29bea16 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -306,7 +306,7 @@ class Chef
# copy Mixlib::CLI over so that it can be configured in knife.rb
# config file
- Chef::Config[:verbosity] = config[:verbosity]
+ Chef::Config[:verbosity] = config[:verbosity] if config[:verbosity]
end
def parse_options(args)
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index 9ccd91775f..5ab8e84eac 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -63,6 +63,12 @@ describe Chef::Knife do
Chef::Knife.reset_config_loader!
end
+ it "does not reset Chef::Config[:verbosity to nil if config[:verbosity] is nil" do
+ Chef::Config[:verbosity] = 2
+ Chef::Knife.new
+ expect(Chef::Config[:verbosity]).to eq(2)
+ end
+
describe "after loading a subcommand" do
before do
Chef::Knife.reset_subcommands!
@@ -309,7 +315,7 @@ describe Chef::Knife do
expect(Chef::Config[:listen]).to be(false)
end
- context "verbosity is greater than zero" do
+ context "verbosity is one" do
let(:fake_config) { "/does/not/exist/knife.rb" }
before do
@@ -327,6 +333,13 @@ describe Chef::Knife do
knife.configure_chef
end
end
+
+ it "does not humanize the exception if Chef::Config[:verbosity] is two" do
+ Chef::Config[:verbosity] = 2
+ allow(knife).to receive(:run).and_raise(Exception)
+ expect(knife).not_to receive(:humanize_exception)
+ expect { knife.run_with_pretty_exceptions }.to raise_error(Exception)
+ end
end
end