Bug #130
Context managers don't account for exceptions
| Status: | Done | Start: | 01/05/2010 | |
| Priority: | Quick | Due date: | ||
| Assigned to: | % Done: | 100% |
||
| Category: | Operations | |||
| Target version: | 0.9.1 | |||
Description
In general, Fabric’s context managers fail to clean up after themselves in case an exception is raised within them. This makes it difficult to use them if you’re trying to do exception handling. For instance, take the following code:
try:
# ... do some stuff here ...
with cd('something'):
# ... do more work here ...
except:
with cd('somewhere'):
# ... do cleanup here ...
If an exception is raised inside with cd('something'), any commands inside the with cd('somewhere') will fail, because they will actually try to cd to something/somewhere, because the first cd never cleaned up after itself.
I think the solution to this is fairly simple, I've implemented it (with a test) here: http://github.com/carljm/fabric/commit/e6eba334a80951c9f3510622f93be8ce6ed9de39
Associated revisions
Revision 7f280a0438326d27ab43f0664632a511d040b7e5
Make context managers restore env upon exception.
Fixes #130.
History
Updated by Jeff Forcier 205 days ago
- Category set to Operations
- Assigned to set to Jeff Forcier
- Target version set to 0.9.1
Thanks for the catch — as usual, the first implementation of stuff tends to be relatively naive. Your point is a good one.
Will fix / pull down your tweak in the near future. Thanks again!
Also, note — leaving a ticket here is fine, no need to also send a GH pull request, it’s just 2x the emails/messages for me to handle ;)
Updated by Carl Meyer 204 days ago
Jeff Forcier wrote:
Also, note — leaving a ticket here is fine, no need to also send a GH pull request, it’s just 2x the emails/messages for me to handle ;)
Yeah. And I also piped up in IRC for the trifecta :–) Just not sure which was the preferred way to get your attention. I’ll just do Redmine in the future. Thanks!
Updated by Jeff Forcier 204 days ago
IRC is a crapshoot, I idle in there all the time but whether I'm actually “there” and listening is kind of random :) I had missed your note until about 3 hours later, I think.
So yea — Redmine is the ticket. (ho ho! get it?)
Updated by Jeff Forcier 63 days ago
- Status changed from Assigned to Done
- % Done changed from 0 to 100
Applied in changeset 7f280a0438326d27ab43f0664632a511d040b7e5.
Also available in: Atom