diff --git a/lib/helpers/gem_exec.rb b/lib/helpers/gem_exec.rb index 905c081e6..295c0cecd 100644 --- a/lib/helpers/gem_exec.rb +++ b/lib/helpers/gem_exec.rb @@ -36,24 +36,25 @@ class GemExec end end - Dir.chdir(working_dir) output_hash = {:output => '', :status => 0, :exception => nil} - begin - # Times out after 30 minutes, (TODO: make this configurable) - output_hash[:output] = ProcessHelper.process("#{gem_path} #{arguments}", {:pty => true, :timeout => (60 * 30), - include_output_in_exception: true}) - rescue Exception => ex - output_hash[:status] = 1 - output_hash[:exception] = ex - if ex.class == ProcessHelper::UnexpectedExitStatusError - output_hash[:output] = ex.to_s.split('Command output: ')[1] - Print.err 'Non-zero exit status...' - elsif ex.class == ProcessHelper::TimeoutError - Print.err 'Timeout: Killing process...' - sleep(30) - output_hash[:output] = ex.to_s.split('Command output prior to timeout: ')[1] - else - output_hash[:output] = nil + Dir.chdir(working_dir) do + begin + # Times out after 30 minutes, (TODO: make this configurable) + output_hash[:output] = ProcessHelper.process("#{gem_path} #{arguments}", {:pty => true, :timeout => (60 * 30), + include_output_in_exception: true}) + rescue Exception => ex + output_hash[:status] = 1 + output_hash[:exception] = ex + if ex.class == ProcessHelper::UnexpectedExitStatusError + output_hash[:output] = ex.to_s.split('Command output: ')[1] + Print.err 'Non-zero exit status...' + elsif ex.class == ProcessHelper::TimeoutError + Print.err 'Timeout: Killing process...' + sleep(30) + output_hash[:output] = ex.to_s.split('Command output prior to timeout: ')[1] + else + output_hash[:output] = nil + end end end output_hash