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

Using Exceptions in Python (server) fails #167

Open
mrlarssen opened this issue Jun 26, 2017 · 5 comments
Open

Using Exceptions in Python (server) fails #167

mrlarssen opened this issue Jun 26, 2017 · 5 comments
Labels

Comments

@mrlarssen
Copy link

mrlarssen commented Jun 26, 2017

I have a node client and a python server, and when trying to raise an Exception in Python, I get the following error:

Mon Jun 26 11:24:13 2017 <Greenlet at 0x7ff6b8da6af0: <bound method Server._async_task of <zerorpc.core.Server object at 0x7ff6b901ec10>>(<zerorpc.events.Event object at 0x7ff6b8da9690>)> failed with BaseException
python_1   | 
python_1   | WARNING:zerorpc.channel:zerorpc.ChannelMultiplexer, unable to route event: <'\x00k\x8bEl'> _zpc_hb {u'response_to': u'6f2baa6b-8304-4bea-a2ee-000000000000', u'message_id': u'6f2baa6b-8304-4bea-a2ee-000000000001', u'v': 3} [...]


node_1     | An error occurred: { HeartbeatError: Lost remote after 10000ms
node_1     |     at Error (native)
node_1     |     at Object.createErrorResponse (/code/node_modules/zerorpc/lib/util.js:53:10)
node_1     |     at ClientChannel.<anonymous> (/code/node_modules/zerorpc/lib/client.js:147:26)
node_1     |     at emitOne (events.js:96:13)
node_1     |     at ClientChannel.emit (events.js:188:7)
node_1     |     at Timeout._repeat (/code/node_modules/zerorpc/lib/channel.js:198:18)
node_1     |     at Timeout.wrapper [as _onTimeout] (timers.js:421:11)
node_1     |     at tryOnTimeout (timers.js:228:11)
node_1     |     at Timer.listOnTimeout (timers.js:202:5) name: 'HeartbeatError' } 

I have seen a previous issue, where a similar error is being addressed. However, the suggested solution seemed to be to use "assert". Asserts are strictly for development purposes, and using Exceptions are therefore preferred (read: needed).

Node (client):

client.invoke("invoke_exception", function (error, result, more) {
        console.error("An error occurred:", error);
 })

Python (server):

 def invoke_exception(self):
        raise Exception("SOME ERROR")

Any suggestions as to how to deal with Exceptions in Python?

Edit: (I thought my example was similar to the one that you have on your website under "First Class Exceptions" at the bottom http://www.zerorpc.io/)

@bombela
Copy link
Member

bombela commented Jun 26, 2017

zerorpc is effectively supposed to convert exception into a zerorpc error. Which should then be sent back to the client. Not sure what is going on here. Is it working with a Python client against a Python server?

@mrlarssen
Copy link
Author

Thank you for your response.

Invoking the same function from a Python Client results in the following:

Traceback (most recent call last):
  File "/usr/local/bin/zerorpc", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/zerorpc/cli.py", line 308, in main
    return run_client(args)
  File "/usr/local/lib/python2.7/site-packages/zerorpc/cli.py", line 267, in run_client
    results = client(args.command, *call_args)
  File "/usr/local/lib/python2.7/site-packages/zerorpc/core.py", line 270, in __call__
    return self._process_response(request_event, bufchan, timeout)
  File "/usr/local/lib/python2.7/site-packages/zerorpc/core.py", line 238, in _process_response
    reply_event, self._handle_remote_error)
  File "/usr/local/lib/python2.7/site-packages/zerorpc/patterns.py", line 45, in process_answer
    raise exception
zerorpc.exceptions.RemoteError: Traceback (most recent call last):
Exception: SOME ERROR

Looks like this is the expected behavior? I assume the error is with node then?

@bombela
Copy link
Member

bombela commented Jun 26, 2017

Effectively, you did get an exception RemoteError from the zerorpc client. Which encapsulates information about the remote error, ...obviously.

So yes, it seems to be a problem between the nodejs client and the python server.

I will try to find some time to debug this. Sorry for the trouble.

@mrlarssen
Copy link
Author

Thank you.

I added:

client.on("error", function(error) {
    console.error("RPC client error:", error);
});

which now gives me the following result:

python_1        | ERROR:zerorpc.core:
python_1        | Traceback (most recent call last):
python_1        | Exception: SOME ERROR
node_1           | An error occurred: { Traceback (most recent call last):
node_1           | Exception: SOME ERROR
node_1           |  name: <Buffer 45 78 63 65 70 74 69 6f 6e> }

@bombela
Copy link
Member

bombela commented Jun 26, 2017

Right, it does seem to be a really awkward way to catch errors though. Will try to look into it.

@bombela bombela added the bug label Aug 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants