Never assume set e works with 3rd party code

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-11-21

I had a deploy script for Heroku:

set -e

heroku run rake db:migrate
... # other commands that must ONLY run if the migration was successful

My migrations on Heroku failed, yet the subsequent commands ran. This is because heroku run rake db:migrate always returns exit code 0 even on error conditions (annoyingly...)

The fix was to scan the output

if heroku run rake db:migrate | grep "rake aborted!"; then
  exit 1
fi

Lessons