Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly wrap Ruby StandardError w/ add'l context #390

Merged
merged 1 commit into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ appear at the top.
## [Unreleased][]

* Your contribution here!
* [#390](https://github.com/capistrano/sshkit/pull/390): Properly wrap Ruby StandardError w/ add'l context - [@mattbrictson](https://github.com/mattbrictson)

## [1.12.0][] (2017-02-10)

Expand Down
2 changes: 1 addition & 1 deletion lib/sshkit/runners/parallel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def execute
Thread.new(host) do |h|
begin
backend(h, &block).run
rescue StandardError => e
rescue ::StandardError => e
e2 = ExecuteError.new e
raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sshkit/runners/sequential.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def execute
private
def run_backend(host, &block)
backend(host, &block).run
rescue StandardError => e
rescue ::StandardError => e
e2 = ExecuteError.new e
raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
end
Expand Down
17 changes: 17 additions & 0 deletions test/unit/runners/test_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "helper"
require "sshkit"

module SSHKit
module Runner
class TestGroup < UnitTest
def test_wraps_ruby_standard_error_in_execute_error
localhost = Host.new(:local)
runner = Group.new([localhost]) { raise "oh no!" }
error = assert_raises(SSHKit::Runner::ExecuteError) do
runner.execute
end
assert_match(/while executing.*localhost/, error.message)
end
end
end
end
18 changes: 18 additions & 0 deletions test/unit/runners/test_parallel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "helper"
require "sshkit"

module SSHKit
module Runner
class TestParallel < UnitTest
def test_wraps_ruby_standard_error_in_execute_error
host = Host.new("deployer@example")
runner = Parallel.new([host]) { raise "oh no!" }
error = assert_raises(SSHKit::Runner::ExecuteError) do
runner.execute
end
assert_match(/deployer@example/, error.message)
assert_match(/oh no!/, error.message)
end
end
end
end
18 changes: 18 additions & 0 deletions test/unit/runners/test_sequential.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "helper"
require "sshkit"

module SSHKit
module Runner
class TestSequential < UnitTest
def test_wraps_ruby_standard_error_in_execute_error
host = Host.new("deployer@example")
runner = Sequential.new([host]) { raise "oh no!" }
error = assert_raises(SSHKit::Runner::ExecuteError) do
runner.execute
end
assert_match(/deployer@example/, error.message)
assert_match(/oh no!/, error.message)
end
end
end
end