panini
panini copied to clipboard
Silent error in middleware
When I mistakenly use function instead coroutine, I got salient error
@app.listen("some.publish.subject")
async def receive_messages(msg):
log.warning(f"got subject {msg.subject}")
log.warning(f"got message {msg.data}")
@app.listen("some.request.subject")
async def receive_messages(msg):
return {'success': True, "data":"some data you asked for"}
class MyMiddleware(Middleware):
async def send_publish(self, subject, message, publish_func, **kwargs):
print('do something before publish')
await publish_func(subject, message, **kwargs)
print('do something after publish')
async def listen_publish(self, msg, cb):
print('do something before listen')
await cb(msg)
print('do something after listen')
async def send_request(self, subject, message, request_func, **kwargs):
print('do something before send request')
result = await request_func(subject, message, **kwargs)
print('do something after send request')
return result
async def listen_request(self, msg, cb):
print('do something before listen request')
result = cb(msg) # error. expected "result = await cb(msg)"
print('do something after listen request')
return result
In fact, it raised error here and that's make sense, but there is no exception in terminal
Could we check "next wrapper kind" before call?
I believe, that we can check next wrapper kind (but only from the MyMiddleware side, if necessary),
But we can't modify the implementation of these methods, that MyMiddleware provides to us,
User must use async def
with await cb(msg)
or def
with cb(msg)
I'm not sure if this problem can be fixed right now
➤ Andrew Volotskov commented:
In fact, it raised error here ( https://github.com/lwinterface/panini/blob/fa72c4027ac9e4b07128169f965566074db40ea7/panini/nats_client/_asyncio_cli.py#L279 ) and that's make sense, but there is no exception in terminal
Could we check "next wrapper kind" before call?