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