middleware
middleware copied to clipboard
Recovery out of the stack
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?
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
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?
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. :)
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.
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.
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.
Is this project still being maintained or has it been abandoned at this point?
@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.
No worries, was just curious as I am using it a few places and having to do some rewrites. Thanks for the update.