utils/fork: handle termsig in safe_fork
This commit is contained in:
		
							parent
							
								
									787e6cb75f
								
							
						
					
					
						commit
						f079373d8c
					
				@ -240,7 +240,14 @@ rescue Exception => e # rubocop:disable Lint/RescueException
 | 
			
		||||
    error_hash["env"] = e.env
 | 
			
		||||
  when "ErrorDuringExecution"
 | 
			
		||||
    error_hash["cmd"] = e.cmd
 | 
			
		||||
    error_hash["status"] = e.status.exitstatus
 | 
			
		||||
    error_hash["status"] = if e.status.is_a?(Process::Status)
 | 
			
		||||
      {
 | 
			
		||||
        exitstatus: e.status.exitstatus,
 | 
			
		||||
        termsig:    e.status.termsig,
 | 
			
		||||
      }
 | 
			
		||||
    else
 | 
			
		||||
      e.status
 | 
			
		||||
    end
 | 
			
		||||
    error_hash["output"] = e.output
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -579,19 +579,32 @@ class ErrorDuringExecution < RuntimeError
 | 
			
		||||
    @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
 | 
			
		||||
      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 (uncaught_signal = status&.termsig)
 | 
			
		||||
      "was terminated by uncaught signal #{Signal.signame(uncaught_signal)}"
 | 
			
		||||
    elsif termsig
 | 
			
		||||
      "was terminated by uncaught signal #{Signal.signame(termsig)}"
 | 
			
		||||
    else
 | 
			
		||||
      raise ArgumentError, "Status neither has `exitstatus` nor `termsig`."
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@ describe ErrorDuringExecution do
 | 
			
		||||
  subject(:error) { described_class.new(command, status: status, output: output) }
 | 
			
		||||
 | 
			
		||||
  let(:command) { ["false"] }
 | 
			
		||||
  let(:status) { instance_double(Process::Status, exitstatus: exitstatus) }
 | 
			
		||||
  let(:status) { instance_double(Process::Status, exitstatus: exitstatus, termsig: nil) }
 | 
			
		||||
  let(:exitstatus) { 1 }
 | 
			
		||||
  let(:output) { nil }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -186,7 +186,7 @@ describe "Exception" do
 | 
			
		||||
  describe ErrorDuringExecution do
 | 
			
		||||
    subject { described_class.new(["badprg", "arg1", "arg2"], status: status) }
 | 
			
		||||
 | 
			
		||||
    let(:status) { instance_double(Process::Status, exitstatus: 17) }
 | 
			
		||||
    let(:status) { instance_double(Process::Status, exitstatus: 17, termsig: nil) }
 | 
			
		||||
 | 
			
		||||
    its(:to_s) { is_expected.to eq("Failure while executing; `badprg arg1 arg2` exited with 17.") }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -51,7 +51,14 @@ module Utils
 | 
			
		||||
          # to rescue them further down.
 | 
			
		||||
          if e.is_a?(ErrorDuringExecution)
 | 
			
		||||
            error_hash["cmd"] = e.cmd
 | 
			
		||||
            error_hash["status"] = e.status.exitstatus
 | 
			
		||||
            error_hash["status"] = if e.status.is_a?(Process::Status)
 | 
			
		||||
              {
 | 
			
		||||
                exitstatus: e.status.exitstatus,
 | 
			
		||||
                termsig:    e.status.termsig,
 | 
			
		||||
              }
 | 
			
		||||
            else
 | 
			
		||||
              e.status
 | 
			
		||||
            end
 | 
			
		||||
            error_hash["output"] = e.output
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user