Raise exception option for sh! #54

joeworkman opened this Issue Oct 12, 2012 · 2 comments

2 participants


I am really loving Methadone. Thank you!

I like the sh! method, however, I wish that there was the ability to raise an exception as well as exiting. Maybe this could be a new method?

If I am running sh from within a class, I feel its bad practice to exit the application form there. Let me know if I am wrong here though.

This is the work around that I can come up with for my classes and it seems to work awesome.

  sh "opens '#{notifyurl}'"
rescue Exception => e 
  raise e.message 

That code just re-raises the exception you've caught, so it doesn't really do anything additional.

sh! actually does raise an exception - that's why it's there. It raises a Methadone::FailedCommandError which, if you do not catch it, will ultimately cause your app to exit. In a methadone-powered app, any unhandled exception is ultimately caught, and the app exits with the message give to the exception.

The idea of sh! is that you would use it for commands that absolutely have to succeed or your program must die. You can customize the error message on a failure via

sh!("ls -l /tmp", :on_fail => "Couldn't ls /tmp?  Uh-oh!")

Now, all that being said, maybe you are doing something I hadn't considered? If this explanation didn't help, post some more code and maybe I can figure out what we need to do…


Assuming my answer helped, so closing. Re-open with more info if I'm missing something in my answer or if you find another problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment