summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXabier de Zuazo <xabier@zuazo.org>2012-11-21 18:54:00 +0100
committerBryan McLellan <btm@opscode.com>2013-04-18 08:48:00 -0700
commit0cd591cc82a15e6529e8730734c359e5f7b1f606 (patch)
tree06d5bad2f1234ac9f87740299e392e8ac9550716
parent305058b7b7eca03019248bd88ca20426a0f0cc11 (diff)
downloadchef-0cd591cc82a15e6529e8730734c359e5f7b1f606.tar.gz
[CHEF-3516] Some knife commands emit Errno::EPIPE when used in a pipeline
-rw-r--r--lib/chef/knife/core/ui.rb15
-rw-r--r--spec/unit/knife/core/ui_spec.rb27
2 files changed, 39 insertions, 3 deletions
diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb
index 85e9612315..f76eecf822 100644
--- a/lib/chef/knife/core/ui.rb
+++ b/lib/chef/knife/core/ui.rb
@@ -64,14 +64,20 @@ class Chef
# Prints a message to stdout. Aliased as +info+ for compatibility with
# the logger API.
def msg(message)
- stdout.puts message
+ begin
+ stdout.puts message
+ rescue Errno::EPIPE
+ end
end
alias :info :msg
# Prints a msg to stderr. Used for warn, error, and fatal.
def err(message)
- stderr.puts message
+ begin
+ stderr.puts message
+ rescue Errno::EPIPE
+ end
end
# Print a warning message
@@ -143,7 +149,10 @@ class Chef
end
def pretty_print(data)
- stdout.puts data
+ begin
+ stdout.puts data
+ rescue Errno::EPIPE
+ end
end
def edit_data(data, parse_output=true)
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index 784ad1f0d7..31555cce43 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -40,7 +40,22 @@ describe Chef::Knife::UI do
end
end
+ shared_examples "an output mehthod handling IO exceptions" do |method|
+ it "should throw Errno::EIO exceptions" do
+ @out.stub(:puts).and_raise(Errno::EIO)
+ @err.stub(:puts).and_raise(Errno::EIO)
+ lambda {@ui.send(method, "hi")}.should raise_error(Errno::EIO)
+ end
+ it "should ignore Errno::EPIPE exceptions (CHEF-3516)" do
+ @out.stub(:puts).and_raise(Errno::EPIPE)
+ @err.stub(:puts).and_raise(Errno::EPIPE)
+ lambda {@ui.send(method, "hi")}.should_not raise_error(Errno::EPIPE)
+ end
+ end
+
describe "output" do
+ it_behaves_like "an output mehthod handling IO exceptions", :output
+
it "formats strings appropriately" do
@ui.output("hi")
@out.string.should == "hi\n"
@@ -187,6 +202,18 @@ EOM
end
end
+ describe "warn" do
+ it_behaves_like "an output mehthod handling IO exceptions", :warn
+ end
+
+ describe "error" do
+ it_behaves_like "an output mehthod handling IO exceptions", :warn
+ end
+
+ describe "fatal" do
+ it_behaves_like "an output mehthod handling IO exceptions", :warn
+ end
+
describe "format_for_display" do
it "should return the raw data" do
input = { :gi => :go }