diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index 0bbbd4275c..e86fa8f6c7 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -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 diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 8db68ba978..0b37cbaa71 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -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 diff --git a/Library/Homebrew/extend/os/linux/keg_relocate.rb b/Library/Homebrew/extend/os/linux/keg_relocate.rb index 8219d73c3e..568e707d16 100644 --- a/Library/Homebrew/extend/os/linux/keg_relocate.rb +++ b/Library/Homebrew/extend/os/linux/keg_relocate.rb @@ -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