Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent error in middleware #39

Open
artas728 opened this issue Mar 9, 2021 · 3 comments
Open

Silent error in middleware #39

artas728 opened this issue Mar 9, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@artas728
Copy link
Collaborator

artas728 commented Mar 9, 2021

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
@artas728 artas728 added the bug Something isn't working label Mar 9, 2021
@artas728
Copy link
Collaborator Author

artas728 commented Mar 9, 2021

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?

@danylott
Copy link
Contributor

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

@Tulsene Tulsene changed the title Salient error in middleware Silent error in middleware Mar 30, 2021
@sync-by-unito
Copy link

sync-by-unito bot commented Apr 12, 2021

➤ Andrew Volotskov commented:

In fact, it raised error here (

f'Expected {"dict" if data_type in [dict, "json.dumps"] else data_type} but got {type(message)}'
) and that's make sense, but there is no exception in terminal

Could we check "next wrapper kind" before call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants