Exception: ErrorDuringExecution

Inherits:
RuntimeError
  • Object
show all
Extended by:
T::Sig
Defined in:
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.

Raises:

  • (ArgumentError)


596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'exceptions.rb', line 596

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 = 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)

Returns the value of attribute cmd.



594
595
596
# File 'exceptions.rb', line 594

def cmd
  @cmd
end

#outputObject (readonly)

Returns the value of attribute output.



594
595
596
# File 'exceptions.rb', line 594

def output
  @output
end

#statusObject (readonly)

Returns the value of attribute status.



594
595
596
# File 'exceptions.rb', line 594

def status
  @status
end

Instance Method Details

#stderrString

Returns:



652
653
654
# File 'exceptions.rb', line 652

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