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 when a system command fails.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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.

Parameters:



845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
# File 'exceptions.rb', line 845

def initialize(cmd, status:, output: nil, secrets: [])
  redacted_cmd = Formatter.redact_secrets(cmd.shelljoin.gsub('\=', "="), secrets)
  cmd = cmd.map do |arg|
    case arg
    when String then Formatter.redact_secrets(arg, secrets)
    when Array then arg.map { |value| Formatter.redact_secrets(value, secrets) }
    when Hash then arg.transform_values { |value| Formatter.redact_secrets(value, secrets) if value }
    else arg
    end
  end
  @cmd = cmd
  @status = status
  output = output&.map { |type, line| [type, Formatter.redact_secrets(line, secrets)] }
  @output = output

  resolved_exitstatus = case status
  when Integer
    status
  when Hash
    status["exitstatus"]
  else
    status.exitstatus
  end
  @exitstatus = T.let(resolved_exitstatus, T.nilable(Integer))

  resolved_termsig = case status
  when Integer
    nil
  when Hash
    status["termsig"]
  else
    status.termsig
  end
  @termsig = T.let(resolved_termsig, T.nilable(Integer))

  reason = if exitstatus
    "exited with #{exitstatus}"
  elsif (t = termsig)
    "was terminated by uncaught signal #{Signal.signame(t)}"
  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 << Array(output).map(&format_output_line).join
    s << "\n" unless s.end_with?("\n")
  end

  super s.freeze
end

Instance Attribute Details

#cmd ⇒ Array<Pathname, String, Array<String>, Hash{String => String, nil}, nil> (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.

Returns:



823
824
825
# File 'exceptions.rb', line 823

def cmd
  @cmd
end

#exitstatus ⇒ Integer? (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.

Returns:



826
827
828
# File 'exceptions.rb', line 826

def exitstatus
  @exitstatus
end

#output ⇒ Array<Array<([String, Symbol], String)>>? (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.

Returns:



835
836
837
# File 'exceptions.rb', line 835

def output
  @output
end

#status ⇒ Integer, ... (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.

Returns:



829
830
831
# File 'exceptions.rb', line 829

def status
  @status
end

#termsig ⇒ Integer? (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.

Returns:



832
833
834
# File 'exceptions.rb', line 832

def termsig
  @termsig
end

Instance Method Details

#stderr ⇒ String

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:



909
910
911
# File 'exceptions.rb', line 909

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