Skip to content

Commit

Permalink
Update error handling to reduce unhandled exceptions (#96)
Browse files Browse the repository at this point in the history
* Update error handling to prevent trying to emit an error when the client is disconnected

* Wrap error emit in try/except per review comment

---------

Co-authored-by: Daniel McKnight <daniel@neon.ai>
  • Loading branch information
NeonDaniel and NeonDaniel authored Jun 28, 2024
1 parent 1dadc43 commit 5833398
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ovos_bus_client/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@ def on_error(self, *args):
LOG.warning('Could not send message because connection has closed')
elif isinstance(error, ConnectionRefusedError):
LOG.warning('Connection Refused. Is Messagebus Service running?')
elif isinstance(error, ConnectionResetError):
LOG.warning('Connection Reset. Did the Messagebus Service stop?')
else:
LOG.exception('=== %s ===', repr(error))
try:
self.emitter.emit('error', error)
except Exception as e:
LOG.exception(f'Failed to emit error event: {e}')

try:
self.emitter.emit('error', error)
if self.client.keep_running:
self.client.close()
except Exception as e:
Expand Down

0 comments on commit 5833398

Please sign in to comment.