Exception: ErrorDuringExecution

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

Overview

Raised by Kernel#safe_system in utils.rb.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ErrorDuringExecution.


538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'Library/Homebrew/exceptions.rb', line 538

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

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

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

  if Array(output).present?
    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


536
537
538
# File 'Library/Homebrew/exceptions.rb', line 536

def cmd
  @cmd
end

#outputObject (readonly)

Returns the value of attribute output


536
537
538
# File 'Library/Homebrew/exceptions.rb', line 536

def output
  @output
end

#statusObject (readonly)

Returns the value of attribute status


536
537
538
# File 'Library/Homebrew/exceptions.rb', line 536

def status
  @status
end

Instance Method Details

#stderrObject


570
571
572
# File 'Library/Homebrew/exceptions.rb', line 570

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