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

mqtt-rpc-client: fix error response handling #6

Merged
merged 4 commits into from
Feb 3, 2023

Conversation

sikmir
Copy link
Contributor

@sikmir sikmir commented Feb 3, 2023

data is optional field in error response, see MQTT-RPC protocol.

Before:

$ mqtt-rpc-client -d wb-device-manager -s bus-scan -m Stop
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3452, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
    rc = self.loop(timeout, max_packets)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1181, in loop
    rc = self.loop_read(max_packets)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1572, in loop_read
    rc = self._packet_read()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2310, in _packet_read
    rc = self._packet_handle()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2936, in _packet_handle
    return self._handle_publish()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3216, in _handle_publish
    self._handle_on_message(message)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3444, in _handle_on_message
    self.on_message(self, self._userdata, message)
  File "/usr/lib/python3/dist-packages/mqttrpc/client.py", line 96, in on_mqtt_message
    MQTTRPCError(result.error["message"], result.error["code"], result.error["data"])
KeyError: 'data'
Traceback (most recent call last):
  File "/usr/bin/mqtt-rpc-client", line 74, in <module>
    main()
  File "/usr/bin/mqtt-rpc-client", line 67, in main
    resp = rpc_client.call(
  File "/usr/lib/python3/dist-packages/mqttrpc/client.py", line 111, in call
    raise err
  File "/usr/lib/python3/dist-packages/mqttrpc/client.py", line 107, in call
    result = future.result(1e100 if timeout is None else timeout)
  File "/usr/lib/python3/dist-packages/mqttrpc/client.py", line 56, in result
    raise TimeoutError()
mqttrpc.client.TimeoutError

After:

$ mqtt-rpc-client -d wb-device-manager -s bus-scan -m Stop
Error: Task is already executing. [-33100]: None

@sikmir sikmir requested a review from webconn February 3, 2023 10:31
@webconn
Copy link
Contributor

webconn commented Feb 3, 2023

Надо было codestyle в отдельном pr затронуть, но уже ладно

@sikmir sikmir merged commit f30c01f into main Feb 3, 2023
@sikmir sikmir deleted the bugfix/fix-error-handling branch February 3, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants