Exception: ErrorDuringExecution

Inherits:
RuntimeError
  • Object
show all
Defined in:
brew/Library/Homebrew/exceptions.rb

Overview

Raised by #safe_system in utils.rb.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, status:, output: nil) ⇒ ErrorDuringExecution

Returns a new instance of ErrorDuringExecution



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'brew/Library/Homebrew/exceptions.rb', line 523

def initialize(cmd, status:, output: nil)
  @cmd = cmd
  @status = status
  @output = output

  exitstatus = if status.respond_to?(:exitstatus)
    status.exitstatus
  else
    status
  end

  s = +"Failure while executing; `#{cmd.shelljoin.gsub(/\\=/, "=")}` exited with #{exitstatus}."

  unless [*output].empty?
    format_output_line = lambda do |type_line|
      type, line = *type_line
      if type == :stderr
        Formatter.error(line)
      else
        line
      end
    end

    s << " Here's the output:\n"
    s << output.map(&format_output_line).join
    s << "\n" unless s.end_with?("\n")
  end

  super s.freeze
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd



519
520
521
# File 'brew/Library/Homebrew/exceptions.rb', line 519

def cmd
  @cmd
end

#outputObject (readonly)

Returns the value of attribute output



521
522
523
# File 'brew/Library/Homebrew/exceptions.rb', line 521

def output
  @output
end

#statusObject (readonly)

Returns the value of attribute status



520
521
522
# File 'brew/Library/Homebrew/exceptions.rb', line 520

def status
  @status
end

Instance Method Details

#stderrObject



554
555
556
# File 'brew/Library/Homebrew/exceptions.rb', line 554

def stderr
  [*output].select { |type,| type == :stderr }.map(&:last).join
end