Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions spec/std/process/status_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ describe Process::Status do

describe "#description" do
it "with exit status" do
Process::Status[0].description.should eq "Process exited normally"
Process::Status[255].description.should eq "Process exited normally"
Process::Status[0].description.should eq "Process exited with status 0"
Process::Status[1].description.should eq "Process exited with status 1"
Process::Status[255].description.should eq "Process exited with status 255"
end

it "on interrupt" do
Expand Down
7 changes: 1 addition & 6 deletions src/process/capture.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ class Process
getter result : Result

def initialize(@args : Enumerable(String), @result : Result)
description = if code = result.status.exit_code?
"Process exited with status #{code}"
else
result.status.description
end
super("Command #{args.inspect} failed: #{description}")
super("Command #{args.inspect} failed: #{result.status.description}")
end
end

Expand Down
11 changes: 8 additions & 3 deletions src/process/status.cr
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,20 @@ class Process::Status
# Returns a textual description of this process status.
#
# ```
# Process.run("true").description # => "Process exited normally"
# Process.run("true").description # => "Process exited with status 0"
# Process.run("false").description # => "Process exited with status 1"
# process = Process.new("sleep", ["10"])
# process.terminate
# process.wait.description # => "Process received and didn't handle signal TERM (15)"
# ```
#
# `ExitReason#description` provides the specific messages for non-signal exits.
# `ExitReason#description` provides the specific messages for abnormal exits.
def description : String
if exit_reason.signal? && (signal = exit_signal?)
if code = exit_code?
"Process exited with status #{code}"
Comment thread
straight-shoota marked this conversation as resolved.
elsif exit_reason.signal? && (signal = exit_signal?)
# `ExitReason::Signal` represents signals that are not covered by more
# specific exit reasons, so we explicitly mention the signal.
"Process received and didn't handle signal #{signal}"
else
exit_reason.description
Expand Down
Loading