Exception: ErrorDuringExecution Private

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

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

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

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a new instance of ErrorDuringExecution.

Raises:

  • (ArgumentError)


682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'exceptions.rb', line 682

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

  raise ArgumentError, "Status cannot be nil." if status.nil?

  exitstatus = case status
  when Integer
    status
  when Hash
    status["exitstatus"]
  else
    status.exitstatus
  end

  termsig = case status
  when Integer
    nil
  when Hash
    status["termsig"]
  else
    status.termsig
  end

  redacted_cmd = Formatter.redact_secrets(cmd.shelljoin.gsub('\=', "="), secrets)

  reason = if exitstatus
    "exited with #{exitstatus}"
  elsif termsig
    "was terminated by uncaught signal #{Signal.signame(termsig)}"
  else
    raise ArgumentError, "Status neither has `exitstatus` nor `termsig`."
  end

  s = "Failure while executing; `#{redacted_cmd}` #{reason}."

  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)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



680
681
682
# File 'exceptions.rb', line 680

def cmd
  @cmd
end

#outputObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



680
681
682
# File 'exceptions.rb', line 680

def output
  @output
end

#statusObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



680
681
682
# File 'exceptions.rb', line 680

def status
  @status
end

Instance Method Details

#stderrString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



738
739
740
# File 'exceptions.rb', line 738

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