I was surprised to discover that, when rake db:drop
(and assumedly Rails' other built-in raketasks) fails, the bash status code is 0.
$ rake db:drop
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
...
$ echo $?
0
Perhaps more surprising, it doesn't even raise an error when the task is invoked from within Rails.
2.3.0 :001 > begin
2.3.0 :002 > Rake::Task["db:drop"].invoke
2.3.0 :003 > puts "After raketask invoked"
2.3.0 :004 > end
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
...
After raketask invoked
Is this intentional? Digging into the source, this seems to simply call execute "DROP DATABASE IF EXISTS #{quote_table_name(name)}"
. This should raise an error on failure. What am I missing?
This is an issue fixed in Rails 5: PR #19924 Explicitly exit with status "1" for create and drop failures
Best solution would be to use Rails 5. :) Otherwise, you're stuck with one of:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With