Skip to content

Commit

Permalink
Refactor use of Statis#exit_code in stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Dec 2, 2024
1 parent 85bc584 commit d2aef01
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ class Crystal::Command
puts "Execute: #{elapsed_time}"
end

if status.exit_reason.normal? && !error_on_exit
exit status.exit_code
if (exit_code = status.exit_code?) && !error_on_exit
exit exit_code
end

if message = exit_message(status)
Expand Down
19 changes: 10 additions & 9 deletions src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -876,16 +876,17 @@ module Crystal

status = $?
unless status.success?
if status.normal_exit?
case status.exit_code
when 126
linker_not_found File::AccessDeniedError, linker_name
when 127
linker_not_found File::NotFoundError, linker_name
end
exit_code = status.exit_code?
case exit_code
when 126
linker_not_found File::AccessDeniedError, linker_name
when 127
linker_not_found File::NotFoundError, linker_name
when nil
# abnormal exit
exit_code = 1
end
code = status.normal_exit? ? status.exit_code : 1
error "execution of command failed with exit status #{status}: #{command}", exit_code: code
error "execution of command failed with exit status #{status}: #{command}", exit_code: exit_code
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/macros/methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ module Crystal
command = "#{Process.quote(original_filename)} #{Process.quote(run_args)}"

message = IO::Memory.new
message << "Error executing run (exit code: #{result.status.exit_code}): #{command}\n"
message << "Error executing run (exit code: #{result.status}): #{command}\n"

if result.stdout.empty? && result.stderr.empty?
message << "\nGot no output."
Expand Down
2 changes: 1 addition & 1 deletion src/process/status.cr
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class Process::Status

# Returns `true` if the process exited normally with an exit code of `0`.
def success? : Bool
normal_exit? && exit_code == 0
exit_code? == 0
end

private def signal_code
Expand Down

0 comments on commit d2aef01

Please sign in to comment.