Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add command output to raised exception if the result code is nonzero.

  • Loading branch information...
commit 7b4383dd9474aeca38fdf012b98b8e476dd21d5a 1 parent ba57c10
@hron hron authored jyurek committed
Showing with 21 additions and 1 deletion.
  1. +6 −1 lib/cocaine/command_line.rb
  2. +15 −0 spec/cocaine/command_line_spec.rb
View
7 lib/cocaine/command_line.rb
@@ -87,7 +87,12 @@ def run(interpolations = {})
raise Cocaine::CommandNotFoundError
end
unless @expected_outcodes.include?($?.exitstatus)
- raise Cocaine::ExitStatusError, "Command '#{command}' returned #{$?.exitstatus}. Expected #{@expected_outcodes.join(", ")}"
+ message = [
+ "Command '#{command}' returned #{$?.exitstatus}. Expected #{@expected_outcodes.join(", ")}",
+ "Here is the command output:\n",
+ output
+ ].join("\n")
+ raise Cocaine::ExitStatusError, message
end
output
end
View
15 spec/cocaine/command_line_spec.rb
@@ -150,6 +150,21 @@
end
end
+ it "adds command output to exception message if the result code is nonzero" do
+ cmd = Cocaine::CommandLine.new("convert",
+ "a.jpg b.png",
+ :swallow_stderr => false)
+ error_output = "Error 315"
+ cmd.stubs(:execute).with("convert a.jpg b.png").returns(error_output)
+ with_exitstatus_returning(1) do
+ begin
+ cmd.run
+ rescue Cocaine::ExitStatusError => e
+ e.message.should =~ /#{error_output}/
+ end
+ end
+ end
+
it "should keep result code in #exitstatus" do
cmd = Cocaine::CommandLine.new("convert")
cmd.stubs(:execute).with("convert").returns(:correct_value)
Please sign in to comment.
Something went wrong with that request. Please try again.