zendesk/racecar

racecar will silently crash if an exception is raised from Cli#new

ColinDKelley opened this issue · 3 comments

Problem Statement

exe/racecar silently discards exceptions because it assumes Cli#run has already rescued and logged them.

rescue
  # Exceptions are printed to STDERR and sent to the error handler
  # in `Racecar::Cli#run`, so we don't need to do anything here.
  exit(1)

But if an exception is raised in Cli#new, this assumption won't be true. The exception will be silently discarded.

Steps to Reproduce

Cause an exception to be raised from Cli#new. For example, cause a typo in a --require:

$ bundle exec racecar --require typo ConsumerClass || echo failed

When you run the above, you will see failed output but not the exception that caused it.

failed

Expected Behavior

When the above is run, the exception should be displayed on stderr (and the error_handler run, if one has been registered):

=> Crashed: NameError: undefined local variable or method `typo' for Cli#...
<backtrace>

failed

Suggested Fix

The easiest and most general fix for this would be to move the rescue block from here out to exe/racecar. This is best practice in case some other code path is later introduced that might also raise. And it would also remove the risk of redundant logging, where we might log an exception, then raise it, then log it again.

I'd be happy to make a PR with the suggested change if you'd like.

dasch commented

Please open a PR and I'll review it!

@dasch Will do!