Skip to content

Commit

Permalink
Fix debug out put for in_directory_fork (#146)
Browse files Browse the repository at this point in the history
When an error is raised inside of `in_directory_fork` it writes over the existing contents so if there's any debug output that was added it gets written over.

This fixes that behavior by making stdout and stderr append to the log file instead of
  • Loading branch information
schneems authored Oct 16, 2020
1 parent 7dc0726 commit f5163f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## HEAD

- Fix App#in_directory_fork not receiving debugging output when an error is raised (https://github.com/heroku/hatchet/pull/146)
- Do not create CI tarball inside cwd to prevent tar "file changed as we read it" warnings.

## 7.3.1
Expand Down
4 changes: 2 additions & 2 deletions lib/hatchet/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ def in_directory
def in_directory_fork(&block)
Tempfile.create("stdout") do |tmp_file|
pid = fork do
$stdout.reopen(tmp_file, "w")
$stderr.reopen(tmp_file, "w")
$stdout.reopen(tmp_file, "a")
$stderr.reopen(tmp_file, "a")
$stdout.sync = true
$stderr.sync = true
in_directory do |dir|
Expand Down
9 changes: 9 additions & 0 deletions spec/hatchet/local_repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
expect(ENV[env_name]).to eq(env_name)
end

it "in directory fork captures stdout even when there is an error" do
expect {
Hatchet::App.new("default_ruby").in_directory_fork do
puts "hello_there"
raise "error"
end
}.to raise_error(/hello_there/)
end

it "repos checked into git" do
begin
fixture_dir = "repo_fixtures/different-folder-for-checked-in-repos/default_ruby"
Expand Down

0 comments on commit f5163f0

Please sign in to comment.