Skip to content

Commit

Permalink
Proper exceptions for error cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Oct 29, 2008
1 parent bb5feef commit 2f23384
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions elock.py
Expand Up @@ -11,6 +11,12 @@ class deque(list):
def popleft(self):
return self.pop(0)

class ResourceLocked(Exception): pass

class NotLocked(Exception): pass

class NotResumable(Exception): pass

class Command(object):

def __init__(self, command, **kwargs):
Expand All @@ -26,8 +32,12 @@ def success(self, value):
self._deferred.callback(value)

def fail(self, status, msg):
# XXX: Need proper exception classes used here.
self._deferred.errback(Exception(msg))
exceptions={
('lock', 409): ResourceLocked,
('unlock', 403): NotLocked}
e=exceptions.get((self.command, status), Exception)
print "Adding exception", e(msg)
self._deferred.errback(e(msg))

class ELock(basic.LineReceiver):
"""The elock protocol."""
Expand Down

0 comments on commit 2f23384

Please sign in to comment.