middleware icon indicating copy to clipboard operation
middleware copied to clipboard

Recovery out of the stack

Open jlambert121 opened this issue 12 years ago • 9 comments

What is the correct way to raise an error partway through the stack and detect it in the previous calls to undo things as needed?

I could wrap each @app.call(env) with begin/rescue and raise errors as needed, but that seems a little inelegant. Is there a better way?

jlambert121 avatar Jan 30 '13 02:01 jlambert121

I guess catch / throw would be more appropriate than begin / rescue.

Check out http://rubylearning.com/blog/2011/07/12/throw-catch-raise-rescue-im-so-confused

chatgris avatar Jan 30 '13 09:01 chatgris

In my case I am looking for unexpected results (errors) rather than just early termination (which I think it is appropriate to raise an error, but could be wrong). Regardless, there isn't a specific method that is instead called when returning back down the stack or anything else special, just normal code handling, correct?

jlambert121 avatar Jan 30 '13 13:01 jlambert121

The answer actually is to either use begin/rescue, which can get nasty because you need to do it everywhere, or to use something like Vagrant's Warden (don't try to understand it, I'll explain).

What Warden does is call the "recover" method on each middleware up the stack if an error occurred down the stack.

I actually plan on pulling a Warden-based runner into this gem at some point soon. This issue can kick me in the butt to do it. :)

mitchellh avatar Jan 30 '13 16:01 mitchellh

I was actually looking at that in Vagrant and decided it wasn't going to be something I was going to be able to port. Right now my stack is pretty simple so I'll just catch errors and move on.

jlambert121 avatar Jan 30 '13 17:01 jlambert121

Awesome. Well eventually I'll pull the Warden behavior into here so you can use it. :) I want to get Vagrant working against this gem instead of using the built-in, so that should be soon.

mitchellh avatar Jan 30 '13 19:01 mitchellh

That would take care of my other concerns with this gem - maintenance and usage. :) Feel free to close this if you'd like unless you'd like it as a reminder/nag. At the moment this would be outside my skill set.

jlambert121 avatar Jan 30 '13 19:01 jlambert121

Is this project still being maintained or has it been abandoned at this point?

jlambert121 avatar Jul 03 '14 12:07 jlambert121

@jlambert121 It is being used in many projects and works great! No bugs known so no maintenance needed. This issue is a feature request and just haven't gotten to it.

mitchellh avatar Jul 03 '14 15:07 mitchellh

No worries, was just curious as I am using it a few places and having to do some rewrites. Thanks for the update.

jlambert121 avatar Jul 03 '14 16:07 jlambert121