Comments (5)
Possible solution: drdaeman/brukva@de1c52fae9b3045e4b75c465c77a26bddd4bb259 (the code somehow feels dirty, though)
from brukva.
It seems more clear to catch only brukva's exceptions (not all exceptions) at forward_error context manager. Inherit brukva exceptions from 1 base class and wrap other exceptions (IOError?) into brukva's exception if it is necessary.
Though I must admin I don't fully understand how error handling works now: why is exceptions passed back to callbacks and what are these callbacks. Can somebody provide high-level description on what is error handling supposed to be? This description can be put into source code comments then.
from brukva.
2drdaeman
Yep, my bad. Callbacks was wrongly called with exception, because in function like Client.execute self.call_callbacks... was placed inside 'with' statement. Simple fix: call_callbacks shift outside from with exception.
One special case is Client.listen, so i added disable&enable method to forward_error context (FYI: evilkost/brukva@3d15814e8 )
2kmike
About error handling. I wanted to eliminate code like this:
...
(error, value) = yield client.async.get('foo')
if error:
handle_error(error)
else:
(error, other_value) = yield client.async.get('bar')
if error:
handle_error(error)
...
I patched brukva.adisp:110-113 6f5514c1 to throw exception from generator if value is instance of Exception.
So now, it look much better:
...
try:
value = yield client.async.get('foo')
other_value = yield client.async.get('bar')
except Exception, e:
handle_error(error)
...
And with context manager forward_error is just syntax sugar:
...
with forward_error(handle_error):
value = yield client.async.get('foo')
other_value = yield client.async.get('bar')
...
from brukva.
Simple fix: call_callbacks shift outside from with exception.
No, just shifting the indentation won't do it. While this fixes the original bug, it'll introduce another one — a callback will be called twice, first with the exception, then with some "failure" result.
This is debatable, but I believe callback're expected to be called only once per request — unless a command is a special case like listen
. Therefore call_callbacks
should be normally called only when no exception occured. This is why I used the try...except...else
. An example illustrating the problem:
#!/usr/bin/env python
import contextlib
@contextlib.contextmanager
def chew_error(callback):
try:
yield callback
except Exception, e:
callback(e)
def callback(result):
print("Got {0!r}".format(result))
def example():
result = "failure"
with chew_error(callback):
raise Exception, "exception"
result = "ok"
callback(result)
if __name__ == "__main__":
example()
from brukva.
Oops.
Although, if shift back callback calling inside with
and restrict error handling, example will be working.
But i think, it's not clean.
def callback(result):
print("Got {0!r}".format(result))
def example():
result = "failure"
with forward_error(callback) as forward:
raise Exception, "exception"
result = "ok"
forward.disable() # restrict error handling
callback(result)
Or add special method to forward_context
class ForwardErrorManager(object):
def ret(self, result):
self.disable()
self.callbacks(result)
self.enable()
def example():
result = "failure"
with forward_error(callback) as forward:
raise Exception, "exception"
result = "ok"
forward.ret(result)
I should think for some time.
from brukva.
Related Issues (20)
- None is passed to Client.listen callback instead of brukva.client.Message instance HOT 7
- Extract adisp and upload it to pypi HOT 2
- Support for P[UN]SUBSCRIBE
- brukva in long polling HOT 12
- Add example
- Trouble disconnecting clients due to ConnectionError HOT 3
- Support for zrevrangebyscore
- Redis set callback not being called. HOT 2
- Client brukva connection HOT 6
- self.connection.readline | GeneratorExit HOT 3
- Possibility of using tornado.gen vs adisp? HOT 3
- Subscribing twice on the same channel prevents further new subscriptions
- Disconnecting a client from Redis leads to a ConnectionError HOT 7
- Install error when installing from the python package index via pip
- Is there a timeout to the redis connection query?
- demos are broken HOT 1
- Python 3 compatibility HOT 1
- Reconnection stops working HOT 4
- Use github.com/antirez/redis-doc to check coverage of commands.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brukva.