Artur-Sulej / excellent_migrations

An Elixir tool for checking safety of database migrations.
MIT License
232 stars 25 forks source link

Correct failure exit code #28

Closed elliotblackburn closed 1 year ago

elliotblackburn commented 1 year ago

System.stop/1 seems to have its status code swallowed by Mix for some reason. I'm not entirely sure why but when checking other implementations such as credo, they are using the exit/1 kernel function instead.

After testing, this properly produces an exit code of 1 for failure cases where previously they were 0, despite the call System.stop(1).

This allows the cli commands to properly halt CI processes and makes building wrapper scripts easier.

Test example

# Call with `mix text_exit && echo $?` to see true exit code
defmodule Mix.Tasks.TestExit do
  use Mix.Task
  require Logger

  def run(args) do
    Logger.info("Trying to exit with status code 1")
    System.stop(1)
  end
end

Corrected example

# Call with `mix text_exit_corrected && echo $?` to see true exit code
defmodule Mix.Tasks.TestExitCorrected do
  use Mix.Task
  require Logger

  def run(args) do
    Logger.info("Trying to exit with status code 1")
    exit({:shutdown, 1})
  end
end
Artur-Sulej commented 1 year ago

Nice catch! Thanks for the contribution. I checked that and indeed it works.

Btw, for the corrected example I managed to print the result with: mix text_exit_corrected; echo $?