Use interleaved output for ErrorDuringExecution.

This commit is contained in:
Markus Reiter 2018-07-19 13:31:40 +02:00
parent 3ff9c5335d
commit 2712fcaa67
3 changed files with 18 additions and 14 deletions

View File

@ -19,6 +19,7 @@ module Hbc
end
def run!
@merged_output = []
@processed_output = { stdout: "", stderr: "" }
odebug command.shelljoin
@ -27,9 +28,11 @@ module Hbc
when :stdout
puts line.chomp if print_stdout?
processed_output[:stdout] << line
@merged_output << [:stdout, line]
when :stderr
$stderr.puts Formatter.error(line.chomp) if print_stderr?
processed_output[:stderr] << line
@merged_output << [:stderr, line]
end
end
@ -85,9 +88,8 @@ module Hbc
def assert_success
return if processed_status&.success?
raise ErrorDuringExecution.new(command,
stdout: processed_output[:stdout],
stderr: processed_output[:stderr],
status: processed_status)
status: processed_status,
output: @merged_output)
end
def expanded_args

View File

@ -526,19 +526,21 @@ end
# raised by safe_system in utils.rb
class ErrorDuringExecution < RuntimeError
def initialize(cmd, status:, stdout: nil, stderr: nil)
def initialize(cmd, status:, output: nil)
s = "Failure while executing; `#{cmd.shelljoin.gsub(/\\=/, "=")}` exited with #{status.exitstatus}."
if stdout
s << "==> Standard Output of failed command:\n"
s << stdout
s << "\n" unless stdout.end_with?("\n")
end
unless [*output].empty?
format_output_line = lambda do |type, line|
if type == :stderr
Formatter.error(line)
else
line
end
end
if stderr
s << "==> Standard Error of failed command:\n"
s << stderr
s << "\n" unless stderr.end_with?("\n")
s << " Here's the output:\n"
s << output.map(&format_output_line).join
s << "\n" unless s.end_with?("\n")
end
super s

View File

@ -21,7 +21,7 @@ class Keg
# Skip ELF files that do not have a .dynstr section.
return if ["cannot find section .dynstr", "strange: no string table"].include?(old_rpath)
unless $CHILD_STATUS.success?
raise ErrorDuringExecution.new(cmd_rpath, stdout: old_rpath, status: $CHILD_STATUS)
raise ErrorDuringExecution.new(cmd_rpath, status: $CHILD_STATUS, output: [:stdout, old_rpath])
end
rpath = old_rpath