Phinx: Status command: exit status code is 1 for both down migrations and uncaught exceptions

Created on 7 Mar 2016  路  6Comments  路  Source: cakephp/phinx

Currently, if running the status command causes an exception to be thrown which bubbles all the way to the top without being caught (like an InvalidArgumentException caused by a missing phinx.yml file on the FileLocator.locate() call), the script's exit code is 1.

The problem is that this is the same code as when there are down migrations (as per my merged changes from this PR), meaning there is no way of determining whether there really are down migrations or the command failed entirely.

I did some digging and I see that Phinx is not catching exceptions at all, meaning its down to the SymfonyComponent\Console\Application.run() method to decide the exit code, and it exits with 1 if there was an uncaught exception with code 0 (the default exit code for a InvalidArgumentException).

The way I see it, we can either:

  • Change the phinx error status code for down migrations from 1 to something else (maybe 3 since 2 is the code for missing migrations?).

    • Pros: simplest option.

    • Cons: not sure if it can be done in the next minor change release (in other words, is it considered a minor change?).

  • Surround the whole Phinx\Console\Command\Status.execute() method with a try/catch block and exit with a different code if an uncaught exception is (now) caught.

    • Pros: definitely a minor change/bugfix.

    • Cons: more complex, might not cover every case (what if there is an exception before or after the execute method?).

I'm happy submitting a PR to fix this, just need some instructions on which option to go for (or any other option I didn't consider).

enhancement

Most helpful comment

it's been a while, but I should be able to come up with something.

All 6 comments

Change the phinx error status code for down migrations from 1 to something else (maybe 3 since 2 is the code for missing migrations?).

@rquadling would you be willing to include this change in the 0.7 release if a PR was made?

A different error code makes sense.

Are you able to provide a patch with your suggested changes as PR?

it's been a while, but I should be able to come up with something.

turns our it was this easy: https://github.com/cakephp/phinx/pull/1325 :-)

Note that this change has not made it to the docs yet. They still report the exit codes as 1 and 2.

@courtney-miles would you like to change the docs for this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alex-barylski picture alex-barylski  路  14Comments

wpillar picture wpillar  路  97Comments

ahmarov picture ahmarov  路  27Comments

BardiaAfshin picture BardiaAfshin  路  14Comments

ricksanchez picture ricksanchez  路  15Comments